Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuickPickOptions unusable typings small fix #30819

Merged
merged 1 commit into from
Jul 26, 2017
Merged

Conversation

amadare42
Copy link
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

@amadare42, thanks for your PR! By analyzing the history of the files in this pull request, we identified @egamma and @jrieken to be potential reviewers.

@msftclas
Copy link

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
Member

jrieken commented Jul 24, 2017

@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 jrieken added the api label Jul 26, 2017
@jrieken
Copy link
Member

jrieken commented Jul 26, 2017

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

@mjbvz
Copy link
Collaborator

mjbvz commented Jul 26, 2017

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.

None yet

5 participants