Skip to content

No high order generics binding #51947

Closed
Closed

Description

@MOZGIII

Bug Report

type GenericBinding<
    F extends <T1>(value: T1) => any,  // take a generic fn with T1 parameter
    T2,                                // also accept a T2 parameter
> = F<T2>;                             // bind the generic of F to T2

This does not work, although #47607 claims to have solved #40542 which is essentially this.

Test:

function myfn<T1>(value: T1) {};

const assert1a: typeof myfn extends (<T>(value: T) => void) ? true : false = true;
const assert1b: (<T>(value: T) => void) extends typeof myfn ? true : false = true;

type Test = GenericBinding<typeof myfn, string>; // bind `T1` at `myfn` to `string`, should get `(value: string) => void`

const assert2a: Test extends ((value: string) => void) ? true : false = true;
const assert2b: ((value: string) => void) extends Test ? true : false = true;

const assert2c: Test extends (<T>(value: T) => void) ? true : false = false;
const assert2d: (<T>(value: T) => void) extends Test ? true : false = false; // broken

🔎 Search Terms

High order generics.
#40542
#47607
#37181

🕗 Version & Regression Information

4.6 till 4.9.

⏯ Playground Link

Playground link with relevant code

💻 Code

See above.

🙁 Actual behavior

Compiler error Type 'F' is not generic.ts(2315).

🙂 Expected behavior

Actual evaluation of generics.

Activity

  1. andrewbranch commented on Dec 20, 2022

    @andrewbranch
    Member

    F is a type, while #47607 and #40542 are about values.

  2. typescript-bot commented on Dec 22, 2022

    @typescript-bot
    Contributor

    This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  3. MOZGIII commented on Dec 23, 2022

    @MOZGIII
    Author

    #40542 is clearly about types, #47607 only partially solves the issue described. If you follow what's going on at the code that is mentioned at #40542, the devs there were unable to meaningfully use the limited solution provided by #47607. I'd say that issue has to be reopened, as well as this one, which poses the same issue but in an explicitly broader sense.

    This issue is marked with Working as intended, is it because it was submitted as a bug?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions