-
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 defaulting to {} instead of any #7505
Comments
I don't think there's any alternative to specifying the type you're getting from |
When you don't specify a type everywhere else in TypeScript the type defaults to |
#6354 would be a better solution here. |
also, you can achieve the same result today by defining an overload. function myFunc(): any;
function myFunc<T>(): T;
function myFunc(): any {
return window['test'];
} |
@robianmcd I think it's because "T" inside of a function acts like Also, unlike the other cases where there is no type specified, there is a type variable here -- |
@mhegazy yeah the issue you linked to would be a good solution. Also I didn't think of overloading the function like that. thanks |
TypeScript Version:
1.7.3
Code
Expected behavior:
The type of
test
isany
so there is no compiler error.Actual behavior:
I get the following error message
myFile.ts(9,18): error TS2339: Property 'a' does not exist on type '{}'.
Use Case
I run into this issue whenever I'm working on an Angular project and using the $http service. The type definition for
$http.get()
is as followsso if you don't explicitly specify what T is you get an error when you try to access the response.
The text was updated successfully, but these errors were encountered: