Skip to content

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

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".FixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions