You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Components have the correct types but are inferring incorrectly:
constButton=polyRef<"button">(({as: As="button", ...props})=>{return<As{...props}/>;});// `event` is of type `any` when it should be of type `React.MouseEvent<HTMLButtonElement, MouseEvent>`<ButtononClick={event=>{}}/>
Note that onClick still has the correct type, it's just that typescript isn't inferring our function. What's weirder is that if you provide an as prop, or explicitly provide a value for the component type, then it will infer correctly.
// both `event`s have the correct type<Button<"button">onClick={event=>{}}/>;<Buttonas="button"onClick={event=>{}}/>;
The text was updated successfully, but these errors were encountered:
nasheomirro
changed the title
Event handlers on polyRef Components do not infer props correctly
Event handlers do not infer props correctly
Jan 8, 2023
After some time the trick with commit 03bf3db is now un-needed, I don't know what changed but it has to be some update to typescript or maybe ts-server (idk).
Components have the correct types but are inferring incorrectly:
Note that
onClick
still has the correct type, it's just that typescript isn't inferring our function. What's weirder is that if you provide anas
prop, or explicitly provide a value for the component type, then it will infer correctly.Helpful links:
kripod/react-polymorphic-types#5
microsoft/TypeScript#44596
The text was updated successfully, but these errors were encountered: