microsoft / microsoft/TypeScript

NoInfer breaks discriminate union autocomplete

Open
#60,253 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms

no infer discriminate union

🕗 Version & Regression Information

Tested on version 5.6.3

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgILIN4ChnLATwAcIAuZAcjnIBodkA3OAGwFdTkBnMKUAcwG4sAXyxZQkWIhQAhTHQLEy5AEY06HYAC92IFgFtl0QSKwKUAVRDAA9iGQBeNMgA+yaYKwwWIBGBt3EJEIwAB4AFWQIAA9IEAATDmRLfwA+AApvfzIAOWsASRAYaHCUgEo5YVFAiGC0jDMlKiFSoA

💻 Code
interface A {
  type: 'a',
  value: string;
}

interface B {
  type: 'b',
  size: number;
}

type Union = A | B;

function accept<T extends Union>(union: NoInfer<T>) {

}

accept({type: 'a'})
🙁 Actual behavior

When trying to autocomplete after writing type a the autocomplete doesn't work (but the result does get type checked):
Image

🙂 Expected behavior

Even with NoInfer it should autocomplete the other properties of the "inferred" discriminate union case as it correctly type checks it if written wrong.

Additional information about the issue

No response

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 with the linked TypeScript Playground reproduction and compare autocomplete behavior with the existing type-checking result for NoInfer and a discriminated union. Done means the remaining properties of the selected union case are offered after entering type 'a', while incorrect values continue to be rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.