Skip to content

Type constraint lost in conditional type #43578

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

Closed
mjbvz opened this issue Apr 7, 2021 · 2 comments Β· Fixed by #43599
Closed

Type constraint lost in conditional type #43578

mjbvz opened this issue Apr 7, 2021 · 2 comments Β· Fixed by #43599
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Apr 7, 2021

Bug Report

πŸ”Ž Search Terms

  • extends
  • contain
  • constraint

πŸ•— Version & Regression Information

4.3.0-dev.20210407

This was working in the TS 4.3 beta

⏯ Playground Link

https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcCCATDAxAllAZxgAUBDKUgW2BmCgBUJsBXAOwGMZcJWCAeeuQDmNAHxwAvHADeAKDgK4AbQDScXKzgBrYIggAzOIKgiYAXQBcR4TVVm4oWqwwE4ACgB0X4QSulWiEpmAJSS4gBuELgY8opxAPzuXh4+VmQU1LSEAjYwdqKhEhFRMXFxVpHRsgC+ANyyQA

πŸ’» Code

export type AddFirstParameterToFunctions<Target> = {
    [K in keyof Target]: Target[K] extends (...args: any[]) => void
        ? (...args: Parameters<Target[K]>) => void
        : void
};

πŸ™ Actual behavior

Parameters<Target[K]> has the error:

Type 'Target[K]' does not satisfy the constraint '(...args: any) => any'.
  Type 'Target[keyof Target]' is not assignable to type '(...args: any) => any'.
    Type 'Target[string] | Target[number] | Target[symbol]' is not assignable to type '(...args: any) => any'.
      Type 'Target[string]' is not assignable to type '(...args: any) => any'

πŸ™‚ Expected behavior

This code previously compiled without errors in the TS 4.3-beta

mjbvz added a commit to mjbvz/vscode that referenced this issue Apr 7, 2021
mjbvz added a commit to microsoft/vscode that referenced this issue Apr 7, 2021
* Pick up new TS 4.3

Also tests adding override keywords for extensions as part of #120675

* Update to daily TS and workaround TS 4.3 issue

Works around microsoft/TypeScript#43578
@DanielRosenwasser
Copy link
Member

It's likely that #43439 changed something up if it's a difference since the beta. @ahejlsberg and @weswigham might want to take a look at this.

@DanielRosenwasser DanielRosenwasser changed the title Type constrain lost in conditional type Type constraint lost in conditional type Apr 7, 2021
@weswigham
Copy link
Member

That PR had a carve out for TypeParameters for compat - it can probably be relatively safely expanded to all TypeVariables to cover this case.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Apr 7, 2021
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.3.1 milestone Apr 7, 2021
digitarald pushed a commit to microsoft/vscode that referenced this issue Apr 8, 2021
* Pick up new TS 4.3

Also tests adding override keywords for extensions as part of #120675

* Update to daily TS and workaround TS 4.3 issue

Works around microsoft/TypeScript#43578
gjsjohnmurray pushed a commit to gjsjohnmurray/vscode that referenced this issue Apr 8, 2021
* Pick up new TS 4.3

Also tests adding override keywords for extensions as part of microsoft#120675

* Update to daily TS and workaround TS 4.3 issue

Works around microsoft/TypeScript#43578
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants