microsoft / microsoft/TypeScript

Generic with default type incorrectly constraint suggestions in code completion

Open
#52,516 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: LS: Completion Lists Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Bug Report

When I have a function with generic constraints with a default value, IDEs' code completion only suggests the default value, despite accepting all constraint values.

https://user-images.githubusercontent.com/12190482/215557275-265d803c-9e1a-431b-896a-b0b670bbfafd.mov

🔎 Search Terms

Generic with default type

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Generic with default type
⏯ Playground Link

Playground link with relevant code

💻 Code
type Options = 'a' | 'b' | 'c'

type Result<T extends Options> = T extends 'a' ? true : false;

declare function func<T extends Options = 'a'>(arg?: T): Result<T>

const result = func('') // Code completion only suggests 'a'
🙁 Actual behavior

IDEs' code completion only suggests the default value.

🙂 Expected behavior

IDEs' code completion should suggest all constraint values.

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

Open the linked TypeScript Playground and reproduce completion for the generic function shown in the issue. Trace the completion behavior for a constrained generic with a default type, then verify that all values from the constraint are suggested while the default remains valid.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.