Skip to content

Problem with declaration file generated from generic extended function #17840

Closed

Description

I have code like so:

export class A<T> {
	//
}
export type Constructor<T> = new (...args: any[]) => T;

export function foo<T extends Constructor<{}>>(Base: T): T & Constructor<{}> {
	return class extends Base {};
}

export class B<T> extends foo<Constructor<A<T>>>(A) {}

(This is an over simplified version of real code just to show the problem)

The generated .d.ts file does not compile

export declare class A<T> {}

export declare type Constructor<T> = new (...args: any[]) => T;

export declare function foo<T extends Constructor<{}>>(Base: T): T & Constructor<{}>;

declare const B_base: Constructor<A<T>> & Constructor<{}>;

export declare class B<T> extends B_base {}

As you can see the extending function is compiled to a const B_Base and since consts can not be generic this line throws an error when using the definition file.

Activity

  1. weswigham commented on Nov 10, 2017

    @weswigham
    Member

    This is now an error, as per #17922

  2. locked and limited conversation to collaborators on Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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