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

Feature Request: Infer React generic class type with JSX #18807

Closed
ccorcos opened this issue Sep 27, 2017 · 3 comments
Closed

Feature Request: Infer React generic class type with JSX #18807

ccorcos opened this issue Sep 27, 2017 · 3 comments
Labels
Domain: JSX/TSX Relates to the JSX parser and emitter Effort: Difficult Good luck. In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@ccorcos
Copy link

ccorcos commented Sep 27, 2017

TypeScript Version: 2.5.2

Code

In the following example, I have a generic component with generic props and it would be awesome if the type of the component was inferred when using JSX.

interface XProps<T> {
	x: T
	fn: (x: T) => void
}

class X<T> extends React.Component<XProps<T>, {}> {}

const x = (
	<X
		x={1}
		fn={x => {
			// x is not inferred as a number
		}}
	/>
)
@DanielRosenwasser
Copy link
Member

Related is #6395. The thing is that this is actually sort of a higher order operation on types as well, so this is either very React-specific or difficult to do.

@DanielRosenwasser DanielRosenwasser added Effort: Difficult Good luck. In Discussion Not yet reached consensus Suggestion An idea for TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter labels Sep 28, 2017
@ccorcos
Copy link
Author

ccorcos commented Sep 28, 2017

I see. I suppose we can follow along with the other issue though. Thanks!

@ccorcos ccorcos closed this as completed Sep 28, 2017
@andrewbranch
Copy link
Member

For cross-referencing completeness, it seems that this sort of does work now, except for the bug demonstrated in #22636.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: JSX/TSX Relates to the JSX parser and emitter Effort: Difficult Good luck. In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants