-
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
Generic type mysteriously fallback to base type #9319
Comments
It seems like the |
Can you make the example self-contained and more clearly indicate what invocation of |
Do you mean not importing EDIT: update |
The root problem is that T's This is a duplicate of #7234, which gives the workaround: infer from an intersection of type parameters instead: function createActioner<A extends ReduxAction, T>(
type: string,
create: T & ((...args: any[]) => A)) {
return {
create,
cast(action: ReduxAction): A {
return action as A;
}
};
} Now calls to |
Nice! Thanks for your excellent work. 👍 |
[x] Many common issues and suggestions are addressed in the FAQ
https://github.com/Microsoft/TypeScript/wiki/FAQ
[x] Search for duplicates before logging new issues (tried my best, couldn't find one)
https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue
[x] Questions are best asked and answered at Stack Overflow
http://stackoverflow.com/questions/tagged/typescript
TypeScript Version:
(1.9.0-dev.20160622)
Code
Expected behavior:
actual.cast(action)
returns generic typeA
Actual behavior:
actual.cast(action)
returns typeReduxAction
What's even more strange is in the source code, it is detected correctly:
But in the consuming side, it is not:
The text was updated successfully, but these errors were encountered: