Closed
Description
TypeScript Version:
1.7.3
Code
window['test'] = {a:1, b:2};
function myFunc<T>(): T
{
return window['test'];
}
let test = myFunc();
console.log(test.a);
Expected behavior:
The type of test
is any
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 follows
get<T>(url: string, config?: IRequestShortcutConfig): IHttpPromise<T>;
so if you don't explicitly specify what T is you get an error when you try to access the response.