Skip to content
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

Quick info displays incorrect type in discriminated union type #55495

Closed
kettanaito opened this issue Aug 24, 2023 · 4 comments Β· Fixed by #56318
Closed

Quick info displays incorrect type in discriminated union type #55495

kettanaito opened this issue Aug 24, 2023 · 4 comments Β· Fixed by #56318
Labels
Bug A bug in TypeScript Domain: Type Display Bugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion Info Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Milestone

Comments

@kettanaito
Copy link

πŸ”Ž Search Terms

quick info, union, discriminated union, wrong info.

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBAGlC8UDeAoKUB2BDAthAXFAOQBWA9gBYZFQA+xA1lsBDfQM7ABOAlhgOZQAZMgC+KUcKgAKNMjnY8hTrwFSk49AG0GEEMu59+AXUJYMICXXnpFBYuSpE57MngAKXMmEIAjMmQANhDmEnL0qOi2uPZETCzOUVDxEADKkADGPABmPBkA0nqESFAZZACuGMCEGOU4vhBcUJrNKACUKCjSJXaEROYgALR2RAA0UFiEAIzjvoTc5RDjrkpQUwBMAMzNbVDszDzsuRDssJ0A9OdQABJkAG6NUPePAEQrEJ7eLwB0UAAqFGgAEdynkGFA+NkyHssCBTjxgERTv4giEMChLlAAO4UHjBcZ8KDZLAZYAExGnF4DF4yYmBQKnSoAE0eWCgODIXGgYC5OEO7B4DwhGBZAA89jx+NhgOUuW1vl0ejE+o5qMs3B8vD4oAtoKJdvtgIdjqcYJ0UEA

πŸ’» Code

type X = {
  name: 'john' | 'kate' | string & {}
} & (
  {
  name: string & {}
  [key: string]: any
} | {
  name: 'john'
  someProp: boolean
}
  | {
    name: 'kate'
    kateSpecificKey: { count: number }
  }
)

({ name: 'any-name', a: 1, b: true, some: 123 }) satisfies X

// Hover over "someProp". The quick info says it's boolean
// while, in fact, it's "any" (falls under a more premissive index signature).
({ name: 'john', someProp: true }) satisfies X

πŸ™ Actual behavior

The quick info prop for someProp displays boolean as if the object matches the discriminated union. It doesn't, as you can observe from the actual type validationβ€”someProp is still any, matching a more permissive index signature.

πŸ™‚ Expected behavior

The quick info must display someProp correctlyβ€”as any.

Additional information about the issue

This is a purely visual issue. The type validation is performed correctly.

@Andarist
Copy link
Contributor

Andarist commented Aug 24, 2023

This one is correct. someProp: true has a boolean type. The purpose of satisfies is to keep the expression's type (and influence it with some contextual type information). As long as the expression's type is assignable to the satisfies operand that's all good.

There is a bug there though but it's a different one:

({ name: 'john', someProp: 'wrong!' }) satisfies X

If we hover over someProp here we might see this:

(property) someProp: boolean

but we really should see:

(property) someProp: string

@kettanaito
Copy link
Author

Thanks for the clarification, @Andarist! Also, if this is a beginner-friendly issue, you may navigate me around and I could be able to contribute πŸ™

@andrewbranch andrewbranch added Bug A bug in TypeScript Help Wanted You can do this Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Domain: Type Display Bugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion Info labels Aug 24, 2023
@andrewbranch andrewbranch added this to the Backlog milestone Aug 24, 2023
@Andarist
Copy link
Contributor

If you are up for it we could try to schedule a pairing session.

@kettanaito
Copy link
Author

I would love to. Let's sync in Twitter/Discord and have this issue fixed.

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: Type Display Bugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion Info Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants