-
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
Infer type for generic. #5652
Comments
No, but you can just omit the type annotation and TypeScript will infer the return type of interface Blabla<T> {
(): T
}
function some() {
return () => {
return 123;
}
}
var f: Blabla<number> = some(); |
It would be very great if typescript infer type in this case.
without return type annotation I should annotate arguments for returning closure (I use ts with |
I had the exact same problem. I solved it like this: interface Action {
// some properties here
}
interface Dispatch {
(action: Action): void
}
interface State {
// some properties here
}
interface Thunk<R> {
(dispatch: Dispatch, getState?: () => State): R
}
function doAction() {
return createThunk((dispatch, getState) => {
return 123;
})
}
function createThunk<T>(f: Thunk<T>): Thunk<T> {
return f
} Have you found a better way? |
Hi!
Seems that some cases of inferring types does not work:
I got compilation error:
Is it possible to infer
number
type forT
?The text was updated successfully, but these errors were encountered: