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

Intellisense doesn't narrow properly when discriminator is a template literal #61347

Open
gordonmleigh opened this issue Mar 4, 2025 · 0 comments Β· May be fixed by #61350
Open

Intellisense doesn't narrow properly when discriminator is a template literal #61347

gordonmleigh opened this issue Mar 4, 2025 · 0 comments Β· May be fixed by #61350
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@gordonmleigh
Copy link

πŸ”Ž Search Terms

"intellisense template literal", "intellisense property union"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried (v4.9.5, v5.8.2)

⏯ Playground Link

No response

πŸ’» Code

I didn't include a playground link since it's an intellisense issue.

type A = {
  id: `A:${string}`;
  a: number;
};

type B = {
  id: `B:${string}`;
  b: number;
};

function foo<T extends A | B>(item: T): void {}

foo({ id: "B:" /* auto-complete here */ });

πŸ™ Actual behavior

When you trigger intellisense, it suggests all the property names of the union, even if it could already narrow it based on what you've typed so far:

Image

If id is a literal rather than a template literal type, the suggestions are properly narrowed.

πŸ™‚ Expected behavior

I think the property suggestions should be limited to the narrowed type, similar to if the discriminant is an ordinary string literal.

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Mar 20, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
2 participants