Closed
Description
I'm using TypeScript 1.6.3 in Visual Studio 2015. The es6-promise declaration I'm using contains:
declare class Promise<R> implements Thenable<R> {
constructor(callback: (resolve : (value?: R | Thenable<R>) => void, reject: (error?: any) => void) => void);
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Promise<U>;
}
The following works with an explicit typing of the Promise generic:
new Promise < { foo: number }>((resolve) => {
resolve({ foo: 1 });
}).then((value) => {
value.foo;
});
However, shouldn't type inference allow the following to work?
new Promise((resolve) => {
resolve({ foo: 1 });
}).then((value) => {
value.foo;
});
Instead, I am getting an error when accessing value.foo that foo does not exist on type '{}'. Why is TypeScript defaulting to the {}
type?