Param0
Get a function's first parameter
Parameter of a function are often passed wrapped into an object, React props is a notable example:
function MyComponent(props: Props) {
return <>...</>;
}
To extract
Props
you can use:import type { Param0 } from "tsafe";
type props = Param0<typeof MyComponent>;
It's kind of the same of doing:
type props = Parameters<typeof MyComponent>[0];
but
declare function fun(): number;
type FunParams = Param0<typeof fun>;
// ^void (instead of never)
and
declare function fun(params?: { foo: string }): void;
type FunParams = Param0<typeof fun>;
// ^ { foo: string; } ( instead of { foo: string; } | undefined )
Last modified 8mo ago