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 Parameter | Description |
|---|---|
|
The |
The parameter types of T.
// [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>;