microsoft / microsoft/TypeScript

Autocomplete on extends keyof generic

Open
#28,662 8 comments 44 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.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.3.0-dev.20181122

Search Terms:

  • autocomplete
  • autocomplete generic
  • generic extends
  • autocomplete keyof extends
  • autocomplete keyof generic

Code

type Except<T, K extends keyof T> = Pick<T, { [P in keyof T]: P extends K ? never : P }[keyof T]>;

interface I1 {
    foo: string;
}
function F1<T extends I1>(): Except<T, ''> { // error is shown but autocomplete is not provided
    //code
    return null;
}

Expected behavior:
Having autocomplete showing when extending a generic

Actual behavior:
Even if error is correctly displayed, no autocomplete is shown for a T extends with a known type on the right hand.

Playground Link:
https://www.typescriptlang.org/play/index.html#src=type%20Except%3CT%2C%20K%20extends%20keyof%20T%3E%20%3D%20Pick%3CT%2C%20%7B%20%5BP%20in%20keyof%20T%5D%3A%20P%20extends%20K%20%3F%20never%20%3A%20P%20%7D%5Bkeyof%20T%5D%3E%3B%0A%0Ainterface%20I1%20%7B%0A%20%20%20%20foo%3A%20string%3B%0A%7D%0Afunction%20F1%3CT%20extends%20I1%3E()%3A%20Except%3CT%2C%20''%3E%20%7B%0A%20%20%20%20%2F%2Fcode%0A%20%20%20%20return%20null%3B%0A%7D

Related Issues:
#16740 - but this one is quite different because it's a keyof issue

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

Reproduce the issue using the provided TypeScript Playground link and the supplied generic extends keyof example. Trace the TypeScript autocomplete path for constraints such as T extends I1; done means completion suggestions appear where the issue currently reports an error without autocomplete, with the existing behavior covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.