[[toc]]
Medium , #infer , #built-in
Implements TS's built-in ReturnType
Answer
Medium , #union , #built-in
Implement TypeScript's Omit
Omit creates a T object with the fields in K omitted.
Answer
Medium , #readonly , #object-keys
Implement a general MyReadonly2
K specifies the set of properties of T that should be set to Readonly. If K is not provided, all properties should be made read-only, just like a normal Readonly
Answer
Medium , #readonly , #object-keys , #deep
Implement a generic DeepReadonly
You can assume that in this challenge we are only dealing with objects. Arrays, functions, classes, etc. don't need to be considered. However, you can still challenge yourself by covering as many different cases as possible.
Answer
Medium , #infer , #tuple , #union
Implements the generic TupleToUnion
Answer
Medium , #application
In JavaScript we often use chainable/Pipeline functions to construct an object, but in TypeScript , can you reasonably attach a type to him?
In this challenge, you can implement the type any way you like - Interface, Type or Class. You need to provide two functions option(key, value) and get() . In option you need to extend the current object type with the provided key and value, and get the final result through get.
You only need to implement this functionality at the type level - there is no need to implement any actual TS/JS logic.
You can assume that key only accepts strings and value accepts any type, you just need to expose the type it is passed without any processing. The same key will only be used once.
Answer
Medium , #array
Implement a generic Last
Answer
Medium , #array
Implement a generic Pop
Extra: Likewise, can you implement Shift , Push and Unshift as well?
Answer
Medium , #array , #built-in
Type the function PromiseAll, which accepts an array of PromiseLike objects, and the return value should be Promise
Answer
Medium , #union , `#map
Sometimes you may want to look up a type in a union type based on a property.
In this challenge, we want to get the corresponding type by searching the public type field in the union type Cat | Dog.
In other words, in the following example, we expect LookUp
Answer
Medium , #template-literal
Implements TrimLeft
Answer
Medium , #template-literal
Implements Trim
Answer
Medium , #template-literal
Implements Capitalize
Answer
Medium , #template-iteral
Implement Replace to replace the first substring From in string S Replace with To.
Answer
Medium , #template-literal
Implement ReplaceAll to replace all substrings From in a string S for To.
Answer
Medium , #arguments
Implement a generic AppendArgument
Answer
Medium , #union
Implement the full permutation of the union type and convert the union type into the union type of all possible fully permuted arrays.
Answers
/type-challenges/type-challenges/issues/614
Note
Medium , #template-literal
p>
Calculates the length of a string, similar to String#length.
Answer
Medium , #array
In this challenge, you need to write a type that accepts an array and returns a flattened array type.
Answer
Medium , #object-keys
Implement a type that adds a new field to the interface. This type receives three parameters and returns an interface type with new fields.
Answer
Medium , #math , #template-literal
Implement an Absolute type that accepts string, number or bigInt type parameters and returns a positive character string.
Answer
Medium , #union , #string
Implement a type that converts the received String parameter into a letter Union.
Answer
Medium , #object
Implement the full permutation of the union type and convert the union type into the union type of all possible fully permuted arrays.
Answer
Medium , #
FooBarBaz -> foo-bar-baz
Answer
Medium , #object
Get the difference attribute in two interface types.
Answer
Medium , #array
Implemented in a type system similar to the any function in Python. The type takes an array and returns true if any element in the array is true, otherwise it returns false. If the array is empty, returns false .
Answer
Medium , #union , #utils
Implement the IsNever type, parse the input T type as never and return true, otherwise return false
Answer
Medium , #union , #utils
Implement the IsUnion type, parse the input T type as a union type and return true, otherwise return false
Answer
Medium
Implements the ReplaceKeys type, which will replace the key value of the type in the union type. If the type does not have this Key, it will be skipped. If there is, it will be replaced.
Answer
Medium
Exclude index signatures from object types.
Answer
/type-challenges/type-challenges/issues/3542
Medium
Implements type PercentageParser. Matches type T according to the rule /^(\+|\-)?(\d*)?(\%)?$/.
The matching result consists of three parts, namely: [positive and negative sign, number, unit]. If there is no match, the default is an empty string.
Answer
Medium
Removes specified characters from a string.
Answer
Medium , Math
Given a positive integer as a type parameter, the return type is required to be the number minus 1.
Answer
Medium , object
Select attributes of the same type from F
Answer
Medium , #object
Retain fields of types not specified in U
Answer
Medium , #template-literal
Implement StartsWith
Answer
Medium , #object
Implement a generic PartialByKeys
K specifies the set of properties of T that should be set to optional. When K is not provided, it behaves like a normal Partial
Answer
Medium , #object
Implement a generic RequiredByKeys
K specifies the set of attributes of T that should be made required. When K is not provided, it behaves like a normal Required
Answer
Medium , #readonly , object-keys
Implement a general type Mutable
Answer
Medium , #object
1
Answer
Medium
Given a tuple containing only strings, and type U, recursively construct the object
Answer
Medium , #tuple
Implement the typed version of array inversion Array.reverse
Answer
Medium , #arguments
Implement type version of lodash _.flip function
Type FlipArguments
Answer
Medium , #array
Flatten the array recursively by depth.
Answer
Medium
Block, Element, Modifier Method (BEM) is a popular naming convention for classes in CSS. For example, a block component would be represented as btn , elements that depend on the block would be represented as btn__price , and modifiers that change the style of a block would be represented as btn--big or btn__price--warning . Implements BEM to generate a string union from these three arguments. where B is a string literal and E and M are string arrays (can be empty).
Answer
Medium , #object
A type version that implements in-order traversal of a binary tree.
Answer
Medium
Implementation type just-flip-object:
Answer
Medium
Implement generic Fibonacci
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
Answer
Medium
Implements type AllCombinations to return all character combinations.
Answer
Medium, #array
Implements type GreaterThan
1
Answer
Medium , #tuple
Implements the Zip
Answer
Medium , #tuple
Implement IsTuple, receive type T and determine whether T is a tuple type
< p> AnswerMedium, #tuple
Implement Chunk
Answer
Medium , tuple
Fill , a commonly used JavaScript function, we use types to implement it. Fill
In order to simulate the real Function, the test may contain some boundary conditions, I hope you like it:)
Answer
Medium
Implement TrimRight
Answer
Medium , #union , #array
Implement a generic Without
Answer
Medium , template-literal
Implements the typed version of Math.trunc . It accepts a string or number and returns the integer part, raising the decimal part
p>
Answer
Medium , #array
Implements the type version of Array.indexOf
Answer
Medium , #array
Implementation type version Array.join
Answer
Medium , #array
Implements the type version of Array.lastIndexOf
Answer
Medium , #array
Implements the type version of Lodash.uniq, which receives the array T and returns the deduplicated T
Answer
Medium
Implements MapTypes
Answer
Medium , #tuple
Constructs a tuple of given length
Answer
Medium
Sometimes we want to limit the range of numbers...eg.
Answer
Medium , #array , #application , #string
Given an array of strings, perform permutations and combinations. It is also useful for types like video controlsList
Answer
Medium , #union
Given an array of unique elements, return all possible subsequences .
A subsequence is a sequence that can be derived from an array by removing some elements or not removing any elements without changing the order of the remaining elements.
Answer