Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contextual property type from a mapped type fails to be provided in JSX #55150

Open
Andarist opened this issue Jul 25, 2023 · 0 comments Β· May be fixed by #52095
Open

Contextual property type from a mapped type fails to be provided in JSX #55150

Andarist opened this issue Jul 25, 2023 · 0 comments Β· May be fixed by #52095
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@Andarist
Copy link
Contributor

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.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Jul 27, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants