-
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
Type query for a result of a function call #6239
Comments
Seems that no. It would be great to do something like:
|
This comment is related: #2710 (comment) |
Duplicate of #4233? |
I have also encountered this problem many times. |
What would be the inferred type in the following situation? function fn<a>(value: a) : { value: a; } { return { value: value }; }
let a: typeof fn; If the answer is @DanielRosenwasser, how feasible is it to allow variables to hold Might be related #5959 |
I think answer should be an error about required type argument, and developer should write let a: typeof fn<number>() to get |
@Strate let b = fn<number>();
let a : typeof b; if this is what you are looking for then it might be better phrased as "Type query for a result of a function call" |
You are right, I'm gonna to change the caption :) |
I'm wondering how this would handle overloaded functions? I guess one must pass in the type of the arguments to let it overload correctly the return type. function f(a: string): string;
function f(a: string, b: number): boolean;
function f(a: string, b?: string | number, c?: string): boolean | string {
return true;
}
typeof f(string, number) // boolean Isn't ellipses function f(a: string): boolean;
typeof f(...) // boolean |
Proposal + implementation that covers this: #6606 |
Is it possible to use
typeof
type query operator to get function's return type?The text was updated successfully, but these errors were encountered: