TypeScript: Maximum call stack exceeded with large object declaration.

TypeScript Version: 2.1.4 (also in 2.1.5 and nightly (2.2.0-dev.20170207))

We have some large generated enums with associated properties stored on an object. These compiled fine using TS 2.0.6, but we’re trying to upgrade to 2.1 to use some of the newer features and running into compile issues. I was able to duplicate in the TypeScript Playground as well (though I can’t share a link because it’s too many lines to encode in the URL).

Code

export const enum UsageType {
	UsageA= 100000,
	UsageB = 100001,
        //...
        UsageZZZ = 100471
};
export const enum PropertyType{
	PropertyA= 100000,
	PropertyB = 100001,
        //...
        PropertyZZZ = 101383
};

export const PropertyTypeProperties: {[id: number]: any} = {
    [PropertyType.PropertyA]: {
        value: 100000,
        description: 'A',
        usageType: UsageType.PropertyA,
        isHistorical: false,
        isAudited: true,
        isReadonly: false
    },
    // each PropertyType enum has a corresponding property on the object...
    [PropertyType.PropertyZZZ ]: {
        value: 100000,
        description: 'ZZZ',
        usageType: UsageType.PropertyX,
        isHistorical: false,
        isAudited: true,
        isReadonly: false
    }
}

Expected behavior: Code Compiles without error.

Actual behavior: RangeError: Maximum call stack size exceeded at substituteBinaryExpression (node_modules\typescript\lib\tsc.js:45886:44) at substituteExpression (node_modules\typescript\lib\tsc.js:45853:28) at Object.onSubstituteNode (node_modules\typescript\lib\tsc.js:45829:24) at emitNodeWithSubstitution (node_modules\typescript\lib\tsc.js:46041:36) at pipelineEmitWithSubstitution (node_modules\typescript\lib\tsc.js:48494:17) at emitNodeWithSourceMap (node_modules\typescript\lib\tsc.js:46316:21) at pipelineEmitWithSourceMap (node_modules\typescript\lib\tsc.js:48486:17) at emitNodeWithComments (node_modules\typescript\lib\tsc.js:46442:17) at pipelineEmitWithComments (node_modules\typescript\lib\tsc.js:48478:17) at emitNodeWithNotification (node_modules\typescript\lib\tsc.js:46059:21) at pipelineEmitWithNotification (node_modules\typescript\lib\tsc.js:48470:17) at emitExpression (node_modules\typescript\lib\tsc.js:48466:13)

It seems like a lot of code that compiled fine with 2.0.6 is now giving me stack overflow errors. I got a past a number where we were importing from index files that were re-exporting classes from other files. I’m fairly certain there weren’t actually any circular references, so I may submit another issue for that if I can find a separate example to duplicate.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

@rkavalap the fix should be in typescript@next tomorrow (5/13).

@MikeMatusz my apologies as I’ve been out of the office on and off for the past month. I will continue to investigate this to see if I can determine what we can change to reduce the call stack size.