microsoft / microsoft/TypeScript

Errors on non-callable unions should be more specific

Open
#29,013 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Error Messages Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

While working on #29011 I realized that the error we produce for unions of things which look callable but for which we cannot synthesize a signature for are lackluster. We report an error like:

Cannot use 'new' with an expression whose type lacks a call or construct signature.

when we could do better and say something like

Cannot use 'new' with an expression whose type lacks a call or construct signature. All members of union type {0} have call or construct signatures, but none are similar enough to resolve a call in a typesafe way.

which would make it far more clear what's going on in these scenarios.

Once #29011 is merged, the conditions can be even more specific, such as

Cannot use 'new' with an expression whose type lacks a call or construct signature. All members of union type {0} have call or construct signatures, but more than one has overloads, which prevents this call from being resolved in a typesafe way.

and

Cannot use 'new' with an expression whose type lacks a call or construct signature. All members of union type {0} have call or construct signatures, but more than one has type parameters, which prevents this call from being resolved in a typesafe way.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the existing diagnostic for “Cannot use 'new' with an expression whose type lacks a call or construct signature” and review the related conditions described alongside #29011. Done means the reported union cases distinguish unsynthesizable signatures, multiple overloads, and multiple type parameters with the more specific messages shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
39/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.