Skip to content

Max call stack size exceeded for class expression with extends clause in static method #20695

Description

TypeScript Version: 2.7.0-dev.201xxxxx

Code

// test.tsexportclassTest{publicstaticcreateSubclass(){returnclassextendsTest{};}}

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:exportclassFoo{}exportclassTest{publicstaticcreateSubclass(){returnclassextendsFoo{};}}

When the class expression is returned by an instance method though, TSC does not fail:

// works:exportclassTest{publiccreateSubclass(){returnclassextendsTest{};}}// result:exportdeclareclassTest{createSubclass(): {new(): {createSubclass(): any;};};}

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions