Skip to content

Instantly share code, notes, and snippets.

@hunghg255
Forked from antfu/GetComponentProps.d.tsx
Created January 21, 2024 15:28
Show Gist options
  • Save hunghg255/195281aa2aeb53cb745d2fad31e7a566 to your computer and use it in GitHub Desktop.
Save hunghg255/195281aa2aeb53cb745d2fad31e7a566 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