TypeScript: Printing JS constructor function type causes out-of-memory error

TypeScript Version: 3.2.2 and 3.3.0-rc

Search Terms: heap out of memory

Code First of all, I don’t expect there to be a valid use case of what I’m describing below. In fact a miss configuration in my build settings lead me to this. However I don’t expect TSC to completely crash. Also I found that TS 3.1 had no problems with the code below so this might be a regression of TS 3.2.

Steps to reproduce the heap OOM

  • npm install chart.js
  • cd into node_modules/chart.js/dist. You should find Chart.min.js there.
  • create a tsconfig.json with the following content
{
  "compilerOptions": {
      "target": "es5",
      "module": "commonjs",
      "downlevelIteration": true,
      "skipDefaultLibCheck": true,
      "moduleResolution": "node",
      "preserveConstEnums": false,
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "jsx": "react",
      "noErrorTruncation": true,
      "noEmitOnError": false,
      "declaration": false,
      "stripInternal": true,
      "inlineSourceMap": true,
      "inlineSources": true,
      "sourceMap": false,
      "jsxFactory": "react",
      "noImplicitAny": true,
      "noImplicitReturns": true,
      "noImplicitThis": true,
      "noFallthroughCasesInSwitch": true,
      "strictNullChecks": true,
      "strictPropertyInitialization": true,
      "strictFunctionTypes": true,
      "noStrictGenericChecks": true,
      "noResolve": true,
      "types": [],
      "importHelpers": false,
      "allowJs": true,
      "checkJs": false
  },
  "files": [
      "./Chart.min.js",
  ],
  "compileOnSave": false
}
  • run tsc -p tsconfig.json --outDir foo and see the JavaScript heap out of memory thrown.

Expected behavior: Emits a file foo/Chart.min.js. TS 3.1.6 finishes this in 1.7 seconds without any errors.

Actual behavior: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Playground Link: N/A

Related Issues: This looks similar to https://github.com/Microsoft/TypeScript/issues/29326 and https://github.com/Microsoft/TypeScript/issues/29511 but I don’t understand it deep enough to tell if it’s a duplicate.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (13 by maintainers)

Most upvoted comments

Here’s the trimmed down example that still crashes:

function Color(obj) {
    this.example = true
};
Color.prototype = {
	negate: function () {return this;},
	lighten: function (ratio) {return this;},
	darken: function (ratio) {return this;},
	saturate: function (ratio) {return this;},
	desaturate: function (ratio) {return this;},
	whiten: function (ratio) {return this;},
	blacken: function (ratio) {return this;},
	greyscale: function () {return this;},
	clearer: function (ratio) {return this;},
	toJSON: function () {return this.rgb();},
};

with this tsconfig:

{
  "compilerOptions": {
      "noErrorTruncation": true,
      "noImplicitAny": true,
      "allowJs": true,
      "outDir": "built"
  },
  "files": [
      "./Chart.js",
  ]
}