Skip to content

Intellisense suggests invalid property values within union objects #53165

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

Closed
Xenomer opened this issue Mar 8, 2023 · 0 comments · Fixed by #53709
Closed

Intellisense suggests invalid property values within union objects #53165

Xenomer opened this issue Mar 8, 2023 · 0 comments · Fixed by #53709
Assignees
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements Fix Available A PR has been opened for this issue Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@Xenomer
Copy link

Xenomer commented Mar 8, 2023

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.76.0
  • OS Version: Windows 11 22H2 (22621.1265)

Steps to Reproduce:

  1. Using the following object union type:
type TestType = {
  key1: 'a',
  key2: '1',
} | {
  key1: 'a',
  key2: '2',
} | {
  key1: 'b',
  key2: '3',
}
  1. Even though key2: '1' | '2' when key1 is 'a', VSCode suggest 1, 2 and 3 as b values:
    image
    The underlying type checker even knows the correct values for key2, and throws a problem if theyre used: (note the key2: "1" | "2" part)
    image

This causes bigger usability problems when used with larger unions and objects where VSCode spills the suggestions with lots of incorrect ones.

@deepak1556 deepak1556 assigned jrieken and unassigned deepak1556 Mar 8, 2023
@jrieken jrieken assigned mjbvz and unassigned jrieken Mar 8, 2023
@mjbvz mjbvz transferred this issue from microsoft/vscode Mar 8, 2023
@mjbvz mjbvz removed their assignment Mar 8, 2023
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Help Wanted You can do this Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements labels Mar 10, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 10, 2023
@MariaSolOs MariaSolOs self-assigned this Apr 3, 2023
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Apr 3, 2023
@ahejlsberg ahejlsberg modified the milestones: Backlog, TypeScript 5.1.0 Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements Fix Available A PR has been opened for this issue Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
8 participants