Skip to content

Type inference of return type changes when function arity changes #11183

@asgerhallas

Description

@asgerhallas

TypeScript Version: 2.0.3 (and 1.8.10)

Code

class Greeter<TData> {
    constructor(options: {
        a: (x: any) => TData,
        b: (y: TData) => any
    }) { }
}

let greeter = new Greeter({ 
    a: () => ({ asger: 'hej' }),  // no parameter
    b: (y) => y.asger // TData is of type { asger: string } and this line compiles
});

let greeter = new Greeter({ 
    a: (x) => ({ asger: 'hej' }), // with parameter
    b: (y) => y.asger // TData is of type {  } and this line does not compile
});

Expected behavior:

I expected type inference to be the same regardless of number of parameters on the function assigned to a.

Actual behavior:

A function with one parameter makes type inference fail and type of TData be {}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions