Skip to content

Faulty declarations file from extending generic base class #17805

@NoelAbrahams

Description

@NoelAbrahams

TypeScript Version: 2.4.1

Code

declare type Newable<TType> = {
    new (...params: any[]): TType;
};  

interface Bar<T>{
    (): T;
}

const FooBar = {};

class Foo<TItem> extends (FooBar as any as Newable<Bar<TItem>>) {

}

Expected behavior:
The generated declaration file should contain the following

declare type Newable<TType> = {
    new (...params: any[]): TType;
};
interface Bar<T> {
    (): T;
}
declare const FooBar: {};
declare const Foo_base: Newable<Bar<any>>;
declare class Foo<TItem> extends Foo_base {
}

Actual behavior:

declare type Newable<TType> = {
    new (...params: any[]): TType;
};
interface Bar<T> {
    (): T;
}
declare const FooBar: {};
declare const Foo_base: Newable<Bar<TItem>>;  // <----- TItem is not defined
declare class Foo<TItem> extends Foo_base {
}

When the generated declarations file is referenced by other code, the compilation fails with

error TS2304: Build:Cannot find name 'TItem'.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions