diff --git a/README.md b/README.md index 9463d97..7c30a59 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ We are open for contributions. If you're planning to contribute please make sure * [`Optional`](#optionalt-k) * [`Partial`](#partialt) _(built-in)_ * [`DeepPartial`](#deeppartialt) +* [`Record`](#recordk-t) _(built-in)_ * [`Required`](#requiredt-k) * [`DeepRequired`](#deeprequiredt) * [`Readonly`](#readonlyt) _(built-in)_ @@ -135,6 +136,8 @@ We are open for contributions. If you're planning to contribute please make sure * [`ReturnType`](#returntypet) _(built-in)_ * [`InstanceType`](#instancetypet) _(built-in)_ +* [`Parameters`](#parameterst) _(built-in)_ +* [`ConstructorParameters`](#constructorparameterst) _(built-in)_ * [`PromiseType`](#promisetypet) * [`Unionize`](#unionizet) * [`Brand`](#brandt-u) @@ -691,6 +694,15 @@ type BinaryItems = ValuesType; Make all properties of object type optional +**Usage:** + +```ts +type Props = { name: string; age: number; visible: boolean }; + +// Expect: { name?: string; age?: number; visible?: boolean } +type PartialProps = Partial; +``` + [⇧ back to top](#table-of-contents) ### `Required` @@ -716,6 +728,28 @@ type Props = Required; Make all properties of object type readonly +**Usage:** + +```ts +type Props = { name: string; age: number }; + +// Expect: { readonly name: string; readonly age: number } +type ReadonlyProps = Readonly; +``` + +[⇧ back to top](#table-of-contents) + +### `Record` _(built-in)_ + +Construct an object type whose keys are `K` and values are `T`. + +**Usage:** + +```ts +// Expect: { a: number; b: number } +type Point = Record<'a' | 'b', number>; +``` + [⇧ back to top](#table-of-contents) ### `Mutable` @@ -743,12 +777,58 @@ Mutable; Obtain the return type of a function +**Usage:** + +```ts +declare function f(): string; +// Expect: string +type R = ReturnType; +``` + [⇧ back to top](#table-of-contents) ### `InstanceType` Obtain the instance type of a class +**Usage:** + +```ts +class C {} +// Expect: C +type I = InstanceType; +``` + +[⇧ back to top](#table-of-contents) + +### `Parameters` _(built-in)_ + +Obtain the parameters of a function type as a tuple. + +**Usage:** + +```ts +declare function f(x: number, y: string): void; +// Expect: [number, string] +type P = Parameters; +``` + +[⇧ back to top](#table-of-contents) + +### `ConstructorParameters` _(built-in)_ + +Obtain the parameters of a constructor function type as a tuple. + +**Usage:** + +```ts +class C { + constructor(x: string, y: number) {} +} +// Expect: [string, number] +type P = ConstructorParameters; +``` + [⇧ back to top](#table-of-contents) ### `Unionize`