Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upFunction signatures not inferred on JSX prop with complex union #29340
Comments
weswigham
added
the
Bug
label
Jan 10, 2019
RyanCavanaugh
added this to the Backlog milestone
Mar 14, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


andrewbranch commentedJan 10, 2019
TypeScript Version: 3.3.0-dev.20190109
Search Terms: react function union inference
Code
Expected behavior:
(Props1 | Props2) & (PropsA | PropsB)expands to(Props1 & PropsA) | (Props1 & PropsB) | (Props2 & PropsA) | (Props2 & PropsB)foo={false}narrows that down to intersections that includePropsBPropsAhas been eliminated, the only valid signature for the propfnis(arg: number[]) => JSX.Elementfn={(arg) => <>{arg.toFixed(3)}</>},argshould be inferred asnumber[], which meansarg.toFixed(3)should be an error.Actual behavior:
argis inferred asanywith diagnostic messageParameter 'arg' implicitly has an 'any' type, but a better type may be inferred from usage. [7044], so there's no compilation error forarg.toFixed(3).Sidenote:
bar={3}shows that this issue is unique to function signatures (I think). It correctly narrows between PropsA and PropsB forbar: stringandbar: number, respectively, and enforces that the prop value matches correctly.Playground Link: anyone have a suggestion for an online playground where I can use JSX and @types/react?
Related Issues: Not sure, didn't find anything that looks similar. Couldn't find any issue mentioning that diagnostic message code.