Skip to content

Instantly share code, notes, and snippets.

@antfu
Last active January 21, 2024 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save antfu/8530c4eaea9757d48be0add57e1ebb47 to your computer and use it in GitHub Desktop.
Save antfu/8530c4eaea9757d48be0add57e1ebb47 to your computer and use it in GitHub Desktop.
type GetComponentProps<T> = T extends React.ComponentType<infer P>
? P
: T extends (props: any) => any
? Parameters<T>
: never;
class ClassComponent extends React.Component<{ a: number }> {
render() {
return <div />;
}
}
const FunctionalComponent = (props: { v: string }) => {
return <div />;
};
type a = GetComponentProps<typeof ClassComponent>;
type b = GetComponentProps<typeof FunctionalComponent>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment