Skip to content

Unexpected generic type inference error #17432

@mjbvz

Description

@mjbvz

From: microsoft/vscode#30819

TypeScript Version: 2.4.2

Code
In a vscode extension:

import *  as vscode from 'vscode'

interface MyPickItem extends vscode.QuickPickItem { }
var items:MyPickItem[];
vscode.window.showQuickPick(items, { 
    placeHolder: "(placeholder)", 
    onDidSelectItem: (item:MyPickItem) => {
        /* Wont copile, error:
            Argument of type '{ placeHolder: string; onDidSelectItem: (item: MyPickItem) => void; }' is not assignable to parameter of type 'QuickPickOptions'.
            Types of property 'onDidSelectItem' are incompatible.
                Type '(item: MyPickItem) => void' is not assignable to type '<T extends QuickPickItem>(item: string | T) => any'.
                Types of parameters 'item' and 'item' are incompatible.
                    Type 'string | T' is not assignable to type 'MyPickItem'.
                    Type 'string' is not assignable to type 'MyPickItem'.
        */
    }
});

Expected behavior:
Since MyPickItem extends QuickPickItem, the above call to vscode.window.showQuickPick should be valid

Actual behavior:
Compiler error

More information about this issue:
From: microsoft/vscode#30819

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs InvestigationThis issue needs a team member to investigate its status.VS Code TrackedThere is a VS Code equivalent to this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions