Skip to content

Type constraint lost in conditional typeΒ #43578

Closed

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

Activity

  1. DanielRosenwasser commented on Apr 7, 2021

    @DanielRosenwasser
    Member

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

  2. changed the title [-]Type constrain lost in conditional type[/-] [+]Type constraint lost in conditional type[/+] on Apr 7, 2021
  3. weswigham commented on Apr 7, 2021

    @weswigham
    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.

  4. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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