Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.11 KB

File metadata and controls

53 lines (39 loc) · 1.11 KB

typelab / utils / ExtractParams

type ExtractParams<T> = T extends Fn<infer Params> ? Params : T extends NewableFn<infer Params> ? Params : T extends Class<infer Params> ? Params : never;

Type that extracts the parameters from Function, Newable Function, or the constructor parameters of a Class type.

Type Parameters

Type Parameter Description

T extends | Fn | NewableFn | Class

The Function, Newable Function or Class type from which parameters will be extracted.

Returns

The parameter types of T.

Example

// [string, number]
type FunctionParams = ExtractParams<(a: string, b: number) => void>;

// [string, number]
type NewableParams = ExtractParams<new (a: string, b: number) => { a: string; b: string }>;

class MyClass { constructor(public a: string, public b: number) {}}
// [string, number]
type ClassParams = ExtractParams<typeof MyClass>;