Skip to content

Generated declarations file omits generic parameter when a recursive type is implied as the return value #11855

Closed
@NoelAbrahams

Description

@NoelAbrahams

TypeScript Version: 2.0.6

Code

app.ts

type Foo<T> = {

    foo<U>(): Foo<U>
};

function foo() {

    return {} as Foo<number>;
}

Expected behavior:

app.d.ts

declare type Foo<T> = {
    foo<U>(): Foo<U>;
};
declare function foo(): Foo<number>;

Actual behavior:

declare type Foo<T> = {
    foo<U>(): Foo<U>;
};
declare function foo(): {
    foo<U>(): Foo;
};

The generated declarations file cannot be referenced by other code because Foo is missing the generic parameter. Furthermore, hovering over function foo in app.ts shows the return value as the expanded type (i.e. shows the whole body of the declaration).

The workaround is to declare Foo as an interface or to annotate the return value for function foo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issueHigh Priority

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions