-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Generics not being inferred in complex case #9107
Comments
Your case could be reformulated in much more simpler manner (even without type Fn<In, Out> = (arg: In) => Out
const compose = <A, B, C>(f:Fn<A,B>, g:Fn<B,C>) => (arg: A) => g(f(arg));
const f = (x: string) => x;
const g = <T>(x: T) => x;
const h1 = compose(f, f); // inferred h1: (arg: string) => string
const h2 = compose(f, g); // inferred h2: (arg: string) => string
const h3 = compose(g, f); // inferred h3: (arg: {}) => string
const h4 = compose(g, g); // inferred h4: (arg: {}) => {} First two cases are ok for you. In the third case you would expect to have |
Actually you should expect it to be
Actually it is of type A simpler repro is: declare function foo<T>(): T;
declare function bar(): string;
declare function baz<T>(f1: () => T, f2: () => T): T;
const quux = baz(foo, bar); Here, you can expect that since |
I disagree that |
(To clarify, I also disagree that |
related to #15680 |
seems like a duplicate of #9366 |
TypeScript Version:
Typescript playground
Code
Expected behavior:
c is of type
(x: HTMLElement[]) => string
Actual behavior:
c is of type
(x: {}) => string
The text was updated successfully, but these errors were encountered: