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

Contextual typing does not flow backward through function return types to the function arguments #5256

Copy link
Copy link
@drarmstr

Description

@drarmstr
Issue body actions

Consider the following case:

class Entry<T> {
    constructor(callback: (v: T) => number) { }
}
interface Widget {
    list: Entry<{ foo: number }>[];
}

var widget: Widget = {
    list: [
        new Entry((v) => v.foo), // Error accessing v.foo
    ]
};

We get a compiler error in the callback accessing v.foo that foo does not exist on type {} since {} is the default type when it is unable to infer the type. However, in this case we know from the Widget definition that T must be typed to {foo:number}. But, it appears TypeScript is not using this as an inference-site to properly determine T.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdAn existing issue was already created

    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.