Bug Report
🔎 Search Terms
contextual type property mapped type inference jsx
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
import React, { ComponentPropsWithRef, ElementType } from "react";
function UnwrappedLink<T extends ElementType = ElementType>(
props: Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as">
) {
return <a></a>;
}
UnwrappedLink({
onClick: (e) => {
// ^? (parameter) e: React.MouseEvent<HTMLAnchorElement, MouseEvent>
},
});
<UnwrappedLink
onClick={(e) => {
// ^? (parameter) e: any
}}
/>;
🙁 Actual behavior
Contextual signature for onClick fails to be computed here when using JSX but it works just fine with a regular function call.
The problem here is that the contextual type of JSX attributes is an intersection as it includes IntrinsicAttributes. Because of that getTypeOfPropertyOfContextualType fails to call substituteIndexedMappedType appropriately - this is something that is being already fixed by #52095
🙂 Expected behavior
Since JSX is roughly meant to be a sugar for function calls both of those should behave the same way.
Bug Report
🔎 Search Terms
contextual type property mapped type inference jsx
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Contextual signature for
onClickfails to be computed here when using JSX but it works just fine with a regular function call.The problem here is that the contextual type of JSX attributes is an intersection as it includes
IntrinsicAttributes. Because of thatgetTypeOfPropertyOfContextualTypefails to callsubstituteIndexedMappedTypeappropriately - this is something that is being already fixed by #52095🙂 Expected behavior
Since JSX is roughly meant to be a sugar for function calls both of those should behave the same way.