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

TS may parse type parameter lists as JSX #26179

Closed
AlexStacker opened this issue Aug 3, 2018 · 5 comments
Closed

TS may parse type parameter lists as JSX #26179

AlexStacker opened this issue Aug 3, 2018 · 5 comments
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter
Milestone

Comments

@AlexStacker
Copy link

AlexStacker commented Aug 3, 2018

TS may mistakenly use generics as jsx,but it's ok on vscode.

TypeScript Version: 3.0.1

Search Terms:
jsx generics, class generics

Code

const a = <T = any>(): Array<T> => {
    return;
}

Expected behavior:

image

Actual behavior:
image

Playground Link:
compile errror:
https://agentcooper.github.io/typescript-play/?jsx=1#code/MYewdgzgLgBAhjAvDAPAFSfMBPAfACgEoAuGAQQCcK5t1cl6BvAWACgYOYKBTKAVwpgA3GwC+QA

but code on this is OK

@basarat
Copy link
Contributor

basarat commented Aug 3, 2018

Its known : https://basarat.gitbooks.io/typescript/content/docs/jsx/react.html#generic-functions

I'm a user just like you just wanted to state that users have known this in the past 🌹

@AlexStacker
Copy link
Author

@basarat Thank you very much for your reply and solved my doubts. If the official can improve this problem, then I feel would be useful.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Aug 3, 2018
@DanielRosenwasser
Copy link
Member

I think we should be able to use lookahead to detect that we definitely have a type parameter list.

@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.1 milestone Aug 3, 2018
@DanielRosenwasser DanielRosenwasser added the Domain: JSX/TSX Relates to the JSX parser and emitter label Aug 3, 2018
@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Aug 3, 2018

We already do some lookahead to look for a comma after the <T; we should also look for =. Note that extends is not a sufficient lookahead becase <foo extends></foo> is legal JSX

@sandersn sandersn changed the title TS may mistakenly use generics as jsx TS may parse type parameter lists as JSX Aug 3, 2018
@sandersn sandersn modified the milestones: TypeScript 3.4.0, Backlog Mar 13, 2019
@sandersn sandersn removed their assignment Jan 7, 2020
@jakebailey
Copy link
Member

This was fixed in #47112, so #47062 was a dupe of this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter
Projects
None yet
Development

No branches or pull requests

6 participants