Skip to content

Type inference algorithm in compiler differs from spec? #2182

Closed
@osdm

Description

@osdm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions