Completed Challenges
Default Generic Arguments
Default generic arguments allow you to optionally pass a generic argument.
Primitive Data Types
Your TypeScript journey starts with these building blocks.
Type Aliases
You can create multiple names for the same type.
Literal Types
TypeScript can be more specific than string
or number
. It can remember literal values.
Index Signatures
Index signatures allow us to handle types where the properties are a non-specific literal value.
The `typeof` Operator
When you need to create a type from existing JavaScript values, typeof
is the tool for the job.
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.
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.
Mapped Object Types
Mapping objects is a foundational skill that allows you to write type translation logic.
Generic Function Arguments
Give generic function types to your functions
Hello World
Hello, World!
In Type Challenges, we use the type system itself to do the assertion.
For this ch
Type Unions
Type unions are a powerful tool that allow you to create a type that's many values all at once.
Readonly
Implement the built-in Readonly<T>
generic without using it.
Constructs a type with all proper
Tuple to Object
Given an array, transform it into an object type and the key/value must be in the provided array.
First of Array
Implement a generic First<T>
that takes an Array T
and returns its first element's type.
For
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
T
those types that are assignable toU
Awaited
If we have a type which is a wrapped type like Promise, how can we get the type which is inside th
If
Implement the util type If<C, T, F>
which accepts condition C
, a truthy value T
, and a falsy
Concat
Implement the JavaScript Array.concat
function in the type system. A type takes the two argument
Includes
Implement the JavaScript Array.includes
function in the type system. A type takes the two argume
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
The `Pick` builtin
TypeScript ships with a Pick
type. Learn how to make it yourself!
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
Absolute
Implement the Absolute
type. A type that take string, number or bigint. The output should be a p
All
Returns true if all elements of the list are equal to the second parameter passed in, false if the
AnyOf
Implement Python liked any
function in the type system. A type takes the Array and returns `true
Append Argument
For given function type Fn
, and any type A
(any in this context means we don't restrict the ty
Append to object
Implement a type that adds a new field to the interface. The type takes the three arguments. The o
BEM style string
The Block, Element, Modifier methodology (BEM) is a popular naming convention for classes in CSS.