Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Type inference defaults to '{}' in call sites. #5254

Copy link
Copy link
@drarmstr

Description

@drarmstr
Issue body actions

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?

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    DiscussionIssues which may not have code impactIssues which may not have code impact

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.