ts-react-default-props
v1.4.0
Published
> All credit goes to [@decademoon and @RobRendell](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11640#issuecomment-345447306).
Downloads
15
Maintainers
Readme
ts-react-default-props
All credit goes to @decademoon and @RobRendell.
Usage
interface IProps {
required: number;
defaulted: number;
}
class Foo extends React.Component<IProps> {
public static defaultProps = {
defaulted: 0
};
}
// Whichever way you prefer... The former does not require a function call
const FooWithDefaultProps = Foo as ComponentTypeWithDefaultProps<typeof Foo>;
const FooWithDefaultProps = withDefaultProps(Foo);
const f1 = <FooWithDefaultProps />; // error: missing 'required' prop
const f2 = <FooWithDefaultProps defaulted={0} />; // error: missing 'required' prop
const f3 = <FooWithDefaultProps required={0} />; // ok
const f4 = <FooWithDefaultProps required={0} defaulted={0} />; // ok