TypeScript Version: 3.4.1, 3.5.1
Search Terms: tagged union optional literal excess properties props
Code
typeButton={tag: 'button';type?: 'submit';};typeAnchor={tag: 'a';type?: string;href: string};typeUnion=Button|Anchor;constobj: Union={tag: 'button',type: 'submit',// no error, bad! :-(href: 'foo',// error, good! :-)href2: 'foo',};If I replace Button with:
typeButton={tag: 'button';type?: string};That is, if I replace the optional string literal with an optional string, then it works as expected (I get an error for the excess prop href), suggesting this is down to the fact that we're using string literals?
TypeScript Version: 3.4.1, 3.5.1
Search Terms: tagged union optional literal excess properties props
Code
If I replace
Buttonwith:That is, if I replace the optional string literal with an optional string, then it works as expected (I get an error for the excess prop
href), suggesting this is down to the fact that we're using string literals?