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

No high order generics binding #51947

Closed
MOZGIII opened this issue Dec 18, 2022 · 3 comments
Closed

No high order generics binding #51947

MOZGIII opened this issue Dec 18, 2022 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@MOZGIII
Copy link

MOZGIII commented Dec 18, 2022

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.

@andrewbranch andrewbranch added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 20, 2022
@andrewbranch
Copy link
Member

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

@typescript-bot
Copy link
Collaborator

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

@MOZGIII
Copy link
Author

MOZGIII commented Dec 23, 2022

#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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants