milesj / babel-plugin-typescript-to-proptypes

Generate React PropTypes from TypeScript interfaces or type aliases.
MIT License
367 stars 25 forks source link

Transform call-signature-only objects to `PropTypes.function` #52

Closed kubijo closed 2 years ago

kubijo commented 3 years ago

When I have a following prop type definition:

type onChange = {
    (k: 'subject', v: string): void;
    (k: 'description', v: string): void;
    (k: 'canContact', v: boolean): void;
    (k: 'attachments', v: $File[]): void;
}

… I get an object PropType on the component, but the correct one would be a function.

Warning: Failed prop type: Invalid prop `onChange` of type `function` supplied to `Feedback`, expected `object`.

Would you consider catching this case and generating function PropType?


https://www.typescriptlang.org/docs/handbook/2/functions.html#call-signatures

milesj commented 2 years ago

Will be supported in the next version.