Skip to content

Stack overflow on recursive type alias #4443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Koloto opened this issue Aug 25, 2015 · 4 comments
Closed

Stack overflow on recursive type alias #4443

Koloto opened this issue Aug 25, 2015 · 4 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@Koloto
Copy link

Koloto commented Aug 25, 2015

Code to reproduce:

//interface TreeNode {
type TreeNode = {
    name: string;
    parent: TreeNode;
}

function getNames(nodes: TreeNode[]): string[] {
    return nodes.map(s => s.name);
}

Compilation error:

(function (exports, require, module, __filename, __dirname) { /*! ************
^
RangeError: Maximum call stack size exceeded
    at instantiateAnonymousType (C:\Users\Koloto\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js)
    at instantiateType (C:\Users\Koloto\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:11775:25)
    at getTypeOfInstantiatedSymbol (C:\Users\Koloto\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:10500:30)
    at getTypeOfSymbol (C:\Users\Koloto\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:10506:24)
    at inferFromProperties (C:\Users\Koloto\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:12766:40)
    at inferFromTypes (C:\Users\Koloto\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:12750:25)
    at inferFromProperties (C:\Users\Koloto\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:12766:25)
    at inferFromTypes (C:\Users\Koloto\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:12750:25)
    at inferFromProperties (C:\Users\Koloto\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:12766:25)
    at inferFromTypes (C:\Users\Koloto\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:12750:25)

If you replace type with interface (uncomment the first line and comment the second), the code is compiled successfully.

I use version 1.5.3, also reproduced in 1.4.

@DanielRosenwasser
Copy link
Member

Confirmed in the latest nightly (1.6.0-dev.20150825).

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Aug 25, 2015
@DanielRosenwasser
Copy link
Member

More minimal repro:

type TreeNode = {
    name: string;
    parent: TreeNode;
}

var nodes: TreeNode[];
nodes.map(n => n.name);

Seems like the invocation of map is what's doing it.

@danquirk danquirk changed the title Compilation error: Maximum call stack size exceeded Stack overflow on recursive type alias Aug 25, 2015
@mhegazy mhegazy added this to the TypeScript 1.6 milestone Aug 25, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Aug 25, 2015

@DanielRosenwasser can you take a look.

@evil-shrike
Copy link

BTW: It's the bug we encountered in #3451 and finally managed to reproduce.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
5 participants