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

Infer the jsx property type #54851

Closed
NWYLZW opened this issue Jul 1, 2023 · 4 comments
Closed

Infer the jsx property type #54851

NWYLZW opened this issue Jul 1, 2023 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@NWYLZW
Copy link

NWYLZW commented Jul 1, 2023

Bug Report

πŸ”Ž Search Terms

jsx, infer property

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about JSX

⏯ Playground Link

import React from 'react'

declare function A(props: {
  children:
    | React.ReactElement<{ test: 'aaaa' | 'bbbb' }>
}): React.ReactElement

declare function B<P extends Record<string, any>>(props: ...

Playground Link

πŸ’» Code

import React from 'react'

declare function A(props: {
  children:
    | React.ReactElement<{ test: 'aaaa' | 'bbbb' }>
}): React.ReactElement

declare function B<P extends Record<string, any>>(props: P): React.ReactElement<P>

const C = <A>
  <B test={'a'} />
  // ^? (property) test: string
  {B({
    test: 'aaaa'
  // ^? (property) test: 'aaaa'
  })}
</A>

πŸ™ Actual behavior

Infer test property is string type in JSX.

πŸ™‚ Expected behavior

Infer test property is 'aaaa' type in JSX.

@Andarist
Copy link
Contributor

Andarist commented Jul 2, 2023

Type-checking this won't work without something like #29818 .

The contextual types here could maybe be improved to aid autocompletions and stuff like that, but it likely wouldn't solve your underlying problem, see this playground

@NWYLZW
Copy link
Author

NWYLZW commented Jul 2, 2023

Type-checking look like works. In fact, I need provide correct keywords hints when typing 'a', such as:
image
When using function not JSX, call a function which is return React.ReactElement type. It provide the correct hints.

@NWYLZW
Copy link
Author

NWYLZW commented Jul 2, 2023

The example is very easy. Actually, my case is use a function and infer the function arguments type.
image
image

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 7, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants