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

Incorrectly merging JSX.IntrinsicElements with other properties / JSX issue? #50177

Closed
alesmenzel opened this issue Aug 4, 2022 · 0 comments · Fixed by #50261
Closed

Incorrectly merging JSX.IntrinsicElements with other properties / JSX issue? #50177

alesmenzel opened this issue Aug 4, 2022 · 0 comments · Fixed by #50261
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@alesmenzel
Copy link

Bug Report

🔎 Search Terms

intersection, merge types, react intrinsic type

🕗 Version & Regression Information

  • This is a crash - No
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about intersection, merge types, react intrinsic type

⏯ Playground Link

Playground link with relevant code

💻 Code

function SomeComponent<T extends 'button' | 'a'>(props: { element?: T } & JSX.IntrinsicElements[T]): JSX.Element {
    // Just so the return value is RectElement, the rendered element doesnt matter
    return <div />
}

function Test<T extends 'button' | 'a'>(el: T) {
    // ✅
	// return <SomeComponent element={el} className='yolo' />

    // ✅
    // return <SomeComponent element={el}>{null}</SomeComponent>

    // ❌ Type '{ element: T; }' is not assignable to type 'IntrinsicElements[T]'.
    // TS here completely ignores the props type "{ element?: T } & JSX.IntrinsicElements[T]" where I specify the element key?
    return <SomeComponent element={el} />
}

🙁 Actual behavior

I am getting Type '{ element: T; }' is not assignable to type 'IntrinsicElements[T]'. error even-though my type is specified as intersection of { element?: T } & JSX.IntrinsicElements[T]. I have checked and there is no element key in the IntrinsicElements - I can prove that by using Omit<JSX.IntrinsicElements[T], 'element'>, which still returns error. Also when extracting the type into a separate type like this

type TEST = { element?: 'button' | 'a' } & JSX.IntrinsicElements['button' | 'a']
type TEST_ELEMENT = TEST['element']
// ✅          ^^ "button" | "a" | undefined

it returns the expected type of element

🙂 Expected behavior

I expect there is no error and that Type '{ element: T; }' is ASSIGNABLE to type '{ element: T; } & IntrinsicElements[T]'..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants