-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 type inference for generic function variable assignment ? #30048
Comments
This is the right behaviour. The generic parameter If you want type inference you should leave type annotation off the declaration of the function. |
the idea is to let interface A<T> {
foo: T;
}
const a: A<number> = { foo: 13 };
//let getA: <T>() => A<T> = () => a;
let getA = () => a;
const b: A<string> = { foo: "13" };
getA = () => b; // <== now error here this is a common pattern that a system assigned a default initial value/logic but later refined with actual implementation that are not known at compile time other than the generic interface they are conformed... maybe there are other ways to accomplish this? |
You want an existential type. You've written that The easiest way would be to make |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.3.1
Search Terms: generic function assignment, generic type infer
Code
Expected behavior:
no compile error
Actual behavior:
compile error:
Playground Link: here
Related Issues:
#17574
#26871
The text was updated successfully, but these errors were encountered: