Skip to content

Unexpected generic type inference error #17432

Closed

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

Activity

  1. added
    VS Code Tracked
    on Jul 26, 2017
  2. added
    Needs Investigation
    on Aug 29, 2017
  3. mjbvz commented on Jul 17, 2018

    @mjbvz
    ContributorAuthor

    No longer seems applicable. Fixed either due to changes in VS Code API or in TypeScript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs InvestigationVS Code Tracked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions