Skip to content

Intellisense does not work with [P in keyof T] #13701

@geverges-oleg

Description

@geverges-oleg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions