Closed
Description
TypeScript Version: 2.7.0-dev.201xxxxx
Code
// test.ts
export class Test {
public static createSubclass() {
return class extends Test { };
}
}
Expected behavior:
TSC should not fail to compile with --declaration
.
Actual behavior:
TSC fails with Maximum call stack size exceeded
:
> tsc --declaration test.ts
/usr/local/lib/node_modules/typescript/lib/tsc.js:59538
throw e;
^
RangeError: Maximum call stack size exceeded
at writeKeyword (/usr/local/lib/node_modules/typescript/lib/tsc.js:21320:30)
at buildSignatureDisplay (/usr/local/lib/node_modules/typescript/lib/tsc.js:22591:21)
at writeObjectLiteralType (/usr/local/lib/node_modules/typescript/lib/tsc.js:22366:25)
at writeLiteralType (/usr/local/lib/node_modules/typescript/lib/tsc.js:22352:21)
at writeAnonymousType (/usr/local/lib/node_modules/typescript/lib/tsc.js:22246:33)
at writeType (/usr/local/lib/node_modules/typescript/lib/tsc.js:22098:25)
at buildTypeDisplay (/usr/local/lib/node_modules/typescript/lib/tsc.js:22061:24)
at buildReturnTypeDisplay (/usr/local/lib/node_modules/typescript/lib/tsc.js:22586:21)
at buildSignatureDisplay (/usr/local/lib/node_modules/typescript/lib/tsc.js:22601:17)
at writeObjectLiteralType (/usr/local/lib/node_modules/typescript/lib/tsc.js:22388:33)
More Details:
Seems like the error is not caused by extending the specific class that owns the static method, but it also fails with other bases:
// fails too:
export class Foo { }
export class Test {
public static createSubclass() {
return class extends Foo { };
}
}
When the class expression is returned by an instance method though, TSC does not fail:
// works:
export class Test {
public createSubclass() {
return class extends Test { };
}
}
// result:
export declare class Test {
createSubclass(): {
new (): {
createSubclass(): any;
};
};
}