Repository navigation
Cannot read property 'flags' of undefined TypeError when running tsc using 3.7.0-beta #34481
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
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:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Activity
Jack-Works commentedon Oct 17, 2019
Also having this problem when try to generate dts for package matrix-js-sdk with the tsconfig:
Version 3.7.0-dev.20191017
{ "compilerOptions": { "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, "allowJs": true /* Allow javascript files to be compiled. */, "declaration": true /* Generates corresponding '.d.ts' file. */, "declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */, "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ } }Jack-Works commentedon Oct 17, 2019
it's working on Version 3.7.0-dev.20190816 but not working on Version 3.7.0-dev.20190820
andrewbranch commentedon Oct 17, 2019
I’m not able to repro Robin Stevens (@PissedCapslock)’s example at all. Jack Works (@Jack-Works)’ example, interestingly, repros on 3.7.0-dev.20190820 as mentioned, works on 3.7.0-dev.20191017, but then crashes with the same error if you turn
esModuleInteropback tofalse🤔andrewbranch commentedon Oct 17, 2019
Actually, Jack Works (@Jack-Works), the error I can reproduce in your repo is
Cannot read property 'kind' of undefinedwith a fairly unrelated stack to what Robin Stevens (@PissedCapslock) shared. What error message are you getting?Jack-Works commentedon Oct 18, 2019
I think get the same exception stack as the Robin Stevens (@PissedCapslock) one
PissedCapslock commentedon Oct 18, 2019
Andrew Branch (@andrewbranch) You are right. It cannot be reproduced with the code in the issue description. I slightly modified the code after posting the issue, and that resolved the bug.
If you remove the following lines again:
you can reproduce the issue. Of course, one can argue that the JS is not correct at that point and that I should fix my JS first :-) .
To make it as easy as possible to reproduce, you can run the following commands:
But not sure if this issue is still worth your time, seeing as I made an error in the Javascript. The only thing that would be nice is a better error message from
tsc. For example, including the problematic file would already be helpful.andrewbranch commentedon Oct 18, 2019
Indeed, I can reproduce it now. Thanks!
andrewbranch commentedon Oct 18, 2019
Minimal-ish repro:
And note a workaround is to tag
Graphicwith/** @constructor */It’s true that your JS doesn’t check, but the reason we didn’t give you a proper error message is because we crashed during compilation. That’s never acceptable, regardless of how wrong your input is. We should be able to give you a good error message if you tried to compile the contents of A Tale of Two Cities, so we should certainly be able to handle almost-correct JavaScript.
PissedCapslock commentedon Oct 19, 2019
Thanks Andrew. Very nice to see how fast this bug went from being reported to being fixed.
mlodato517 commentedon Jan 8, 2020
Quick question on this because I feel like I may be seeing something similar.
Was the fix in #34577 to use exactly
Object.defineProperty(Foo.prototype, ...as an indicator thatFoois a class?Basically, I'm running into an issue from a custom downloaded portion of Highcharts. I think what's happening is the code has:
And I'm getting
Am I running into the same error as above but because Highcharts uses a hand-rolled
extendinstead ofObject.defineProperty, typescript isn't picking up the class-ness? If so, where can I throw that/** @constructor */to workaround this? I tried:but neither of those worked.
Edit
Is it supposed to be
@constructs?Edit2
That seems to have fixed it