Medium
Get Return Type
Implement the built-in ReturnType<T>
generic without using it.
For example
const fn = (v
Omit
Implement the built-in Omit<T, K>
generic without using it.
Constructs a type by picking all pr
Readonly 2
Implement a generic MyReadonly2<T, K>
which takes two type argument T
and K
.
K
specify th
Deep Readonly
Implement a generic DeepReadonly<T>
which make every parameter of an object - and its sub-object
Tuple to Union
Implement a generic TupleToUnion<T>
which covers the values of a tuple to its values union.
For
Chainable Options
Chainable options are commonly used in Javascript. But when we switch to TypeScript, can you prope
Last of Array
TypeScript 4.0 is recommended in this challenge
Implement a generic Last<T>
that takes an Arr
Pop
TypeScript 4.0 is recommended in this challenge
Implement a generic Pop<T>
that takes an Arra
Promise.all
Type the function PromiseAll
that accepts an array of PromiseLike objects, the returning value s
Type Lookup
Sometimes, you may want to look up a type in a union by its attributes.
In this challenge, we wou
Trim Left
Implement TrimLeft<T>
which takes an exact string type and returns a new string with the whitesp
Trim
Implement Trim<T>
which takes an exact string type and returns a new string with the whitespace
Capitalize
Implement Capitalize<T>
which converts the first letter of a string to uppercase and leave the r
Replace
Implement Replace<S, From, To>
which replace the string From
with To
once in the given strin
ReplaceAll
Implement ReplaceAll<S, From, To>
which replace the all the substring From
with To
in the gi
Append Argument
For given function type Fn
, and any type A
(any in this context means we don't restrict the ty
Permutation
Implement permutation type that transforms union types into the array that includes permutations o
Length of String
Compute the length of a string literal, which behaves like String#length
.
Append to object
Implement a type that adds a new field to the interface. The type takes the three arguments. The o
Absolute
Implement the Absolute
type. A type that take string, number or bigint. The output should be a p
String to Union
Implement the String to Union type. Type take string argument. The output should be a union of inp
Merge
Merge two types into a new type. Keys of the second type overrides keys of the first type.
For ex
KebabCase
Replace the camelCase
or PascalCase
string with kebab-case
.
FooBarBaz
-> foo-bar-baz
F
Diff
Get an Object
that is the difference between O
& O1
AnyOf
Implement Python liked any
function in the type system. A type takes the Array and returns `true
IsNever
Implement a type IsNever, which takes input type T
.
If the type of resolves to never
, return `
IsUnion
Implement a type IsUnion
, which takes an input type T
and returns whether T
resolves to a un
ReplaceKeys
Implement a type ReplaceKeys, that replace keys in union types, if some type has not this key, jus
Remove Index Signature
Implement RemoveIndexSignature<T>
, exclude the index signature from object types.
For example:
Percentage Parser
Implement PercentageParser.
According to the /^(\+|\-)?(\d*)?(\%)?$/
regularit
Drop Char
Drop a specified char from a string.
For example:
type Butterfly = DropChar<' b u t t e r
MinusOne
Given a number (always positive) as a type. Your type should return the number decreased by one.
PickByType
From T
, pick a set of properties whose type are assignable to U
.
For Example
t
StartsWith
Implement StartsWith<T, U>
which takes two exact string types and returns whether T
starts wit
EndsWith
Implement EndsWith<T, U>
which takes two exact string types and returns whether T
ends with `U
PartialByKeys
Implement a generic PartialByKeys<T, K>
which takes two type argument T
and K
.
K
specify
RequiredByKeys
Implement a generic RequiredByKeys<T, K>
which takes two type argument T
and K
.
K
specif
Mutable
Implement the generic Mutable<T>
which makes all properties in T
mutable (not readonly
OmitByType
From T
, pick a set of properties whose type are not assignable to U
.
For Example
ObjectEntries
Implement the type version of Object.entries
For example
interface Model {
Shift
Implement the type version of Array.shift
For example
type Result = Shift<[3
Tuple to Nested Object
Given a tuple type T
that only contains string type, and a type U
, build an object rec
Reverse
Implement the type version of Array.reverse
For example:
type a = Reverse<['
Flip Arguments
Implement the type version of lodash's _.flip
.
Type FlipArguments<T>
requires functio
FlattenDepth
Recursively flatten array up to depth times.
For example:
type a = FlattenDepth<[1
BEM style string
The Block, Element, Modifier methodology (BEM) is a popular naming convention for classes in CSS.
Flip
Implement the type of just-flip-object
. Examples:
Flip<{ a: "x", b: "y", c: "z" }
Fibonacci Sequence
Implement a generic Fibonacci<T>
that takes a number T
and returns its corresponding [Fibonacc
AllCombinations
Implement type AllCombinations<S>
that return all combinations of strings which use characte
Greater Than
In This Challenge, You should implement a type GreaterThan<T, U>
like T > U
Negative numbers
Zip
In This Challenge, You should implement a type Zip<T, U>
, T and U must be Tuple
type exp
IsTuple
Implement a type IsTuple
, which takes an input type T
and returns whether T
is t
Chunk
Do you know lodash
? Chunk
is a very useful function in it, now let's implement it.
`Chunk<T, N
Fill
Fill
, a common JavaScript function, now let us implement it with types.
`Fill<T, N, Start?, End?
Trim Right
Implement TrimRight<T>
which takes an exact string type and returns a new string with the whites
Without
Implement the type version of Lodash.without, Without<T, U> takes an Array T, number or array U an
Trunc
Implement the type version of Math.trunc
, which takes string or number and returns the integ
IndexOf
Implement the type version of Array.indexOf, indexOf<T, U> takes an Array T, any U and returns the
Join
Implement the type version of Array.join, Join<T, U> takes an Array T, string or number U and retu
LastIndexOf
Implement the type version of Array.lastIndexOf
, LastIndexOf<T, U>
takes an Array ```
Unique
Implement the type version of Lodash.uniq, Unique takes an Array T, returns the Array T without
MapTypes
Implement MapTypes<T, R>
which will transform types in object T to different types defined by ty
Construct Tuple
Construct a tuple with a given length.
For example
type result = ConstructTuple<2> // expe
Number Range
Sometimes we want to limit the range of numbers... For examples.
type result = NumberRange<2
Combination
Given an array of strings, do Permutation & Combination. It's also useful for the prop types like
Subsequence
Given an array of unique elements, return all possible subsequences.
A subsequence is a seque
CheckRepeatedChars
Implement type CheckRepeatedChars<S>
which will return whether type S
contains duplica
FirstUniqueCharIndex
Given a string s, find the first non-repeating character in it and return its index. If it does no
Parse URL Params
You're required to implement a type-level parser to parse URL params string into an Union.
GetMiddleElement
Get the middle element of the array by implementing a GetMiddleElement
method, represented by an
Appear only once
Find the elements in the target array that appear only once. For example:input: `[1,2,2,3,3,4,5,6,
Count Element Number To Object
With type CountElementNumberToObject
, get the number of occurrences of every item from an arra
Integer
Please complete type Integer<T>
, type T
inherits from number
, if T
is an integer return it
ToPrimitive
Convert a property of type literal (label type) to a primitive type.
For example
t
DeepMutable
Implement a generic DeepMutable which make every parameter of an object - and its sub-objects r
All
Returns true if all elements of the list are equal to the second parameter passed in, false if the
Filter
Implement the type Filter<T, Predicate>
takes an Array T
, primitive type or union primitive ty
FindAll
Given a pattern string P and a text string T, implement the type FindAll<T, P>
that returns an A
Combination key type
- Combine multiple modifier keys, but the same modifier key combination cannot appear.
- In the
Permutations of Tuple
Given a generic tuple type T extends unknown[]
, write a type which produces all permutations o
Replace First
Implement the type ReplaceFirst<T, S, R> which will replace the first occurrence of S in a tuple T
Transpose
The transpose of a matrix is an operator which flips a matrix over its diagonal; that is, it switc
JSON Schema to TypeScript
Implement the generic type JSONSchema2TS which will return the TypeScript type corresponding to th
Square
Given a number, your type should return its square.
Triangular number
Given a number N, find the Nth triangular number, i.e. 1 + 2 + 3 + ... + N
CartesianProduct
Given 2 sets (unions), return its Cartesian product in a set of tuples, e.g.
CartesianProd
MergeAll
Merge variadic number of types into a new type. If the keys overlap, its values should be merged i
CheckRepeatedTuple
Implement type CheckRepeatedChars<T>
which will return whether type T
contains duplicated memb
Public Type
Remove the key starting with _
from given type T
.
ExtractToObject
Implement a type that extract prop value to the interface. The type takes the two arguments. The o
Deep Omit
Implement a typeDeepOmit
, Like Utility types [Omit](https://www.typescriptlang.org/docs/handbook
IsOdd
return true is a number is odd
Tower of hanoi
Simulate the solution for the Tower of Hanoi puzzle. Your type should take the number of rings as
Pascal's triangle
Given a number N, construct the Pascal's triangle with N rows. [Wikipedia](https://en.wikipedia.o
IsFixedStringLiteralType
Sometimes you may want to determine whether a string literal is a definite type. For example, when
Compare Array Length
Implement CompareArrayLength
to compare two array length(T & U).
If length of T array is gre
Defined Partial Record
Defined Partial Record
Using a Record with union types as keys doesn't allow you to make
Longest Common Prefix
Longest Common Prefix
Write a type, LongestCommonPrefix
that returns the longest common p
Trace
The trace of a square matrix is the sum of the elements on its main diagonal. However, it's diffic
IsAlphabet
Determine if the given letter is an alphabet.