Skip to content

Type constraint lost in conditional typeΒ #43578

Closed
@mjbvz

Description

@mjbvz

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions