Skip to content

Cannot read property 'flags' of undefined TypeError when running tsc using 3.7.0-beta #34481

@PissedCapslock

Description

@PissedCapslock

TypeScript Version: 3.7.0-dev.20191015

Search Terms:
getFlowTypeOfReference
Code

Project structure:

<project_root>
  |_ package.json
  |_ node_modules
  |_ tsconfig.json
  |_ src
      |_ Graphic.js

where package.json is

{
  "name": "tsc-error",
  "description": "sample project to reproduce an error using tsc",
  "version": "0.1",
  "devDependencies": {
    "typescript": "^3.7.0-dev.20191015"
  }
}

and tsconfig.json is

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "declaration": true,
    "allowJs": true
  },
  "lib": [
    "es5","es2015", "es6", "dom"
  ],
  "include": ["src"],
  "exclude": [ "node_modules" ]
}

and Graphic.js a JS file which still uses AMD modules

define([
], function() {

  var NULL_WRITABLE_HIDDEN = Object.freeze({
  });

  function Graphic() {
    Object.defineProperty(this, "_onlineResource", NULL_WRITABLE_HIDDEN);
    Object.defineProperty(this, "_inlineContent", NULL_WRITABLE_HIDDEN);
  }

  Graphic.prototype = Object.create(Object.prototype);
  Graphic.prototype.constructor = Graphic;

  Object.defineProperty(Graphic.prototype, "inlineContent", {
    get: function() {
      return this._inlineContent;
    },
    set: function(ic) {
      this._inlineContent = ic;
      this._onlineResource = null;
    }
  });

  return Graphic;
});

Running the tsc command produces an error.

Expected behavior:
The Typescript compiler can finish compilation without crashing

Actual behavior:
Typescript compiler threw an error

/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:78447
                throw e;
                ^

TypeError: Cannot read property 'flags' of undefined
    at getFlowTypeOfReference (/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:41966:80)
    at tryGetThisTypeAt (/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:43110:32)
    at checkThisExpression (/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:43081:24)
    at checkExpressionWorker (/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:48519:28)
    at checkExpression (/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:48473:38)
    at checkOptionalExpression (/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:40156:24)
    at checkPropertyAccessExpressionOrQualifiedName (/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:44878:22)
    at checkPropertyAccessExpression (/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:44866:20)
    at checkExpressionWorker (/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:48546:28)
    at checkExpression (/tmp/tsc-problem/node_modules/typescript/lib/tsc.js:48473:38)

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions