Skip to content

Better errors when accidentally calling type-assertion expressions #26991

Closed
@DanielRosenwasser

Description

@DanielRosenwasser
declare function foo(): string;

foo()
(document.getElementById("lelement") as HTMLDivElement).id;

@mousetraps just ran into this totally garbage error message

[ts] Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.

Given

  1. A call expression with one argument
  2. whose open paren starts on the next line
  3. and whose sole argument is an AsExpression/TypeAssertionExpression

we should give a specialized error that ends in:

It is highly likely that you are missing a semicolon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Error MessagesThe issue relates to error messagingEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Experience EnhancementNoncontroversial enhancementsFixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions