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 algorithm in compiler differs from spec? #2182

Copy link
Copy link
@osdm

Description

@osdm
Issue body actions

4.12.2 spec says:

Proceeding from left to right, each argument expression e is inferentially typed
...
When a function expression is inferentially typed (section 4.9.3) and a type assigned to a
parameter in that expression references type parameters for which inferences are being made, the
corresponding inferred type arguments to become fixed and no further candidate inferences are
made for them.

But it works differently in compiler. For example:

    function f<T, U>(y: T, f: (x: T) => U, x: T): [T, U] { return [y, f(x)]; }
    interface A { a: A; }
    interface B extends A { b; }

    var a: A, b: B;

    var d = f(b, x => x.a, a); // type [A, A]
    var d2 = f(b, x => x.a, null); // type [B, A]

If "no further candidate inferences were made", then types of d and d2 would be the same. But they are different.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueSpecIssues related to the TypeScript language specificationIssues related to the TypeScript language specification

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    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.