Skip to content

QuickPickOptions unusable typings small fix - #30819

Merged
Johannes Rieken (jrieken) merged 1 commit into
microsoft:masterfrom
amadare42:master
Jul 26, 2017
Merged

Johannes Rieken (jrieken) merged 1 commit into
microsoft:masterfrom
amadare42:master

Conversation

@amadare42

Copy link
Copy Markdown
Contributor

When calling vscode.window.showQuickPick with custom type items, onDidSelectItem callback cannot be correctly typed:

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'.
        */
    }
});

That because of way which typescript handles generic constraints ( microsoft/TypeScript#3410 (comment) ). So easy fix to make it usable is to just change constraint to base QuickPickItem interface.

@mention-bot

Copy link
Copy Markdown

Igor Polishchuk (@amadare42), thanks for your PR! By analyzing the history of the files in this pull request, we identified Erich Gamma (@egamma) and Johannes Rieken (@jrieken) to be potential reviewers.

@msftclas

This seems like a small (but important) contribution, so no Contribution License Agreement is required at this point. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

@jrieken

Copy link
Copy Markdown
Contributor

Mohamed Hegazy (@mhegazy) Can you shed some light on this? This is the signature in question: onDidSelectItem?<T extends QuickPickItem>(item: T | string): any; Is this just because TypeScript doesn't support the usage of generic types in function and its params anymore. It sounds like a shortcut has been taken and the consequence is that we have to change (break?) our API

@jrieken

Copy link
Copy Markdown
Contributor

Merging for being compile errors free, tho I still don't understand this. Matt Bierner (@mjbvz) Can you bring this up in the next TS sync?

@mjbvz

Copy link
Copy Markdown
Contributor

Thanks. I've opened microsoft/TypeScript#17432 to track this issue

@github-actions github-actions Bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants