Skip to content

Object member completions are offered from all union constituents even after union has been discriminated #39438

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

Open
aloifolia opened this issue Jul 6, 2020 · 1 comment
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor
Milestone

Comments

@aloifolia
Copy link

TypeScript Version: 3.9.5 (probably more)

Search Terms:

Code

type Choice = {
    kind: number, x: 42
} | {
    kind: undefined, y: 42
}

const c: Choice = {kind: undefined, X_OR_Y: 42} // X_OR_Y is a placeholder

Expected behavior:
When you use autocompletion to replace X_OR_Y by x or y, the editor should suggest y, only:
Screenshot 2020-07-06 at 13 08 01

Actual behavior:
The editor suggests both x or y:
Screenshot 2020-07-06 at 13 11 32

Of course, if you choose x, the compiler will then complain about the wrongly typed assignment.

Playground Link:
Playground

Related Issues:

@aloifolia aloifolia changed the title undefined breaks autocompletion for union type *undefined* breaks autocompletion for union type Jul 6, 2020
@aloifolia aloifolia changed the title *undefined* breaks autocompletion for union type undefined breaks autocompletion for union type Jul 6, 2020
@aloifolia aloifolia changed the title undefined breaks autocompletion for union type undefined field breaks autocompletion for union type of objects Jul 6, 2020
@aloifolia aloifolia changed the title undefined field breaks autocompletion for union type of objects autocompletion of object fields in union type broken when discriminated fields have type undefined Jul 6, 2020
@aloifolia aloifolia changed the title autocompletion of object fields in union type broken when discriminated fields have type undefined autocompletion of object fields in union type broken when discriminating fields have type undefined Jul 6, 2020
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor labels Jul 10, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jul 10, 2020
@andrewbranch andrewbranch changed the title autocompletion of object fields in union type broken when discriminating fields have type undefined Object member completions are offered from all union constituents even after union has been discriminated Jan 28, 2021
@andrewbranch
Copy link
Member

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: Completion Lists The issue relates to showing completion lists in an editor
Projects
None yet
Development

No branches or pull requests

3 participants