microsoft / microsoft/TypeScript

Intellisense does not work with [P in keyof T]

Open
#13,701 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 2.1.5

Code

//Operators available for the object fields
export type Operators<T> = {
    $elementMatch?: T | Operators<T>;
    $in?: T[];
}

//Filter declaration. 
export type Filter<T> = {
    //field, you can assign a value, or an operator.
    [P in keyof T]: Operators<T[P]> | T[P];
}

function query<T>(filter: Filter<T>) {  }

//Sample class
class Sample {
    foo: string;
    bar: number;
}

query<Sample>({
    //We want to put on the "foo" operator "$in"
    value: {
        //Intellisense then no output
    }
});



Expected behavior:
Intellisense should display all available options.
For example:
$elementMatch
$in

Actual behavior:
Intellisense does not offer anything.
If the "[P in key of T]" is replaced by "[key: string]", then the Intellisense for operators begins to work, but in this case we lose the test fields.

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 IntelliSense failure using the TypeScript 2.1.5 sample with Operators, Filter, and query. Start by tracing completion handling for the mapped type [P in keyof T]; done means the $elementMatch and $in options appear inside the operator object without losing the mapped field checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience
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.