Completed Challenges
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
Implement the built-in Readonly<T> generic without using it.
Constructs a type with all proper
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
Tuple to Object
Given an array, transform it into an object type and the key/value must be in the provided array.
Hello World
Hello, World!
In Type Challenges, we use the type system itself to do the assertion.
For this ch
First of Array
Implement a generic First<T> that takes an Array T and returns its first element's type.
For
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
Length of Tuple
For given a tuple, you need create a generic Length, pick the length of the tuple
For example:
Exclude
Implement the built-in Exclude<T, U>
Exclude from
Tthose types that are assignable toU
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
Awaited
If we have a type which is a wrapped type like Promise, how can we get the type which is inside th
Append Argument
For given function type Fn, and any type A (any in this context means we don't restrict the ty
If
Implement the util type If<C, T, F> which accepts condition C, a truthy value T, and a falsy
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
Concat
Implement the JavaScript Array.concat function in the type system. A type takes the two argument
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
Includes
Implement the JavaScript Array.includes function in the type system. A type takes the two argume
AnyOf
Implement Python liked any function in the type system. A type takes the Array and returns `true
Push
Implement the generic version of Array.push
For example:
type Result = Push<
Unshift
Implement the type version of Array.unshift
For example:
type Result = Unshi
Parameters
Implement the built-in Parameters generic without using it.
For example:
const foo = (a
Generic Function Arguments
Give generic function types to your functions
Generic Type Arguments
Generic types are like function arguments.
Generic Type Constraints
Generic type constraints allow us to restrict the possible types a generic type will accept.
Index Signatures
Index signatures allow us to handle types where the properties are a non-specific literal value.
Indexed Types
Some types can be indexed to lookup a particular value.
The `keyof` operator
keyof allows us to extract a union of another type's keys.
Literal Types
TypeScript can be more specific than string or number. It can remember literal values.
Mapped Object Types
Mapping objects is a foundational skill that allows you to write type translation logic.
The `Pick` builtin
TypeScript ships with a Pick type. Learn how to make it yourself!
Primitive Data Types
Your TypeScript journey starts with these building blocks.
Type Aliases
You can create multiple names for the same type.
The `typeof` Operator
When you need to create a type from existing JavaScript values, typeof is the tool for the job.
Default Generic Arguments
Default generic arguments allow you to optionally pass a generic argument.
Type Unions
Type unions are a powerful tool that allow you to create a type that's many values all at once.