Closed
Description
TypeScript Version: 2.9.2
Search Terms: react component props union types defaultprops
Code
Using the new support for defaultProps
in TypeScript 3.0 re. #24422
{
type Props = { shared: string } & (
| {
type: 'foo';
foo: string;
}
| {
type: 'bar';
bar: string;
});
class Component extends ReactComponent<Props> {
static defaultProps = {
shared: 'yay',
};
}
<Component type="foo" />; // Expected error, got none
// Unexpected error
// Property 'foo' does not exist on type 'Defaultize<Props, { shared: string; }>'.
<Component type="foo" foo="1" />;
}
/cc @mhegazy who requested that I open an issue to discuss/track this.