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

Gracefully parse and error on unparenthesized function/constructor types #39548

Closed
DanielRosenwasser opened this issue Jul 10, 2020 · 2 comments · Fixed by #39570
Closed

Gracefully parse and error on unparenthesized function/constructor types #39548

DanielRosenwasser opened this issue Jul 10, 2020 · 2 comments · Fixed by #39570
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@DanielRosenwasser
Copy link
Member

Motivated by #39546

type Foo = string | () => string;

type InstOrConst<T> = T | new () => T;

Playground Link

We made a decision to disallow function and constructor shorthand types in these contexts, but as a result we have really poor error recovery.

Exported type alias 'Foo' has or is using private name ''.(4081)
Type expected.(1110)
';' expected.(1005)
'string' only refers to a type, but is being used as a value here.(2693)
Cannot find name 'new'.(2304)
Exported type alias 'InstOrConst' has or is using private name 'new'.(4081)
';' expected.(1005)
Cannot find name 'T'.(2304)

We should be able to issue an error in these contexts:

Function type notation must be parenthesized when used in a union type.
Constructor type notation must be parenthesized when used in a union type.
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Help Wanted You can do this Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Domain: Error Messages The issue relates to error messaging labels Jul 10, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jul 10, 2020
@uhyo
Copy link
Contributor

uhyo commented Jul 11, 2020

I'll try this one tomorrow 🙂

@DanielRosenwasser
Copy link
Member Author

Thank you @uhyo!

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: Error Messages The issue relates to error messaging Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
3 participants