Skip to content
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

Crash: TypeError: Cannot read property 'kind' of undefined (at isConstraintPosition) #26978

Closed
calebsander opened this issue Sep 8, 2018 · 5 comments · Fixed by #27246
Closed
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output

Comments

@calebsander
Copy link
Contributor

TypeScript Version: 3.1.0-dev.20180907

Search Terms: compile error strict mode

Code:
test.ts:

class Abc {
  def: boolean
  constructor() {
    this.def = true
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "strict": true
  }
}

Expected behavior:
Running tsc successfully compiles the module.

Actual behavior:
tsc exits with the following error:

node_modules/typescript/lib/tsc.js:68651
                throw e;
                ^

TypeError: Cannot read property 'kind' of undefined
    at isConstraintPosition (node_modules/typescript/lib/tsc.js:36644:27)
    at getConstraintForLocation (node_modules/typescript/lib/tsc.js:36653:25)
    at getInitialOrAssignedType (node_modules/typescript/lib/tsc.js:35754:20)
    at getTypeAtFlowAssignment (node_modules/typescript/lib/tsc.js:36094:71)
    at getTypeAtFlowNode (node_modules/typescript/lib/tsc.js:36028:32)
    at getFlowTypeOfReference (node_modules/typescript/lib/tsc.js:35993:51)
    at isPropertyInitializedInConstructor (node_modules/typescript/lib/tsc.js:44521:28)
    at checkPropertyInitialization (node_modules/typescript/lib/tsc.js:44504:50)
    at checkClassLikeDeclaration (node_modules/typescript/lib/tsc.js:44360:17)
    at checkClassDeclaration (node_modules/typescript/lib/tsc.js:44262:13)

The code compiles successfully if the strict flag is disabled. Also, the code compiles fine if def is instead a number or string (and assigned the appropriate type of value).

@j-oliveras
Copy link
Contributor

The last that works is 3.1.0-dev.20180825:

C:\code\test>node_modules\.bin\tsc.cmd -v
Version 3.1.0-dev.20180825

C:\code\test>node_modules\.bin\tsc.cmd -p tsconfig.json

The first version that fails is 3.1.0-dev.20180828 (after a weekend):

C:\code\test>node_modules\.bin\tsc.cmd -v
Version 3.1.0-dev.20180828

C:\code\test>node_modules\.bin\tsc.cmd -p tsconfig.json
C:\code\test\node_modules\typescript\lib\tsc.js:68212
                throw e;
                ^

TypeError: Cannot read property 'kind' of undefined
    at isConstraintPosition (C:\code\test\node_modules\typescript\lib\tsc.js:36319:27)
    at getConstraintForLocation (C:\code\test\node_modules\typescript\lib\tsc.js:36328:25)
    at getInitialOrAssignedType (C:\code\test\node_modules\typescript\lib\tsc.js:35494:20)
    at getTypeAtFlowAssignment (C:\code\test\node_modules\typescript\lib\tsc.js:35819:71)
    at getTypeAtFlowNode (C:\code\test\node_modules\typescript\lib\tsc.js:35753:32)
    at getFlowTypeOfReference (C:\code\test\node_modules\typescript\lib\tsc.js:35718:51)
    at isPropertyInitializedInConstructor (C:\code\test\node_modules\typescript\lib\tsc.js:44131:28)
    at checkPropertyInitialization (C:\code\test\node_modules\typescript\lib\tsc.js:44114:50)
    at checkClassLikeDeclaration (C:\code\test\node_modules\typescript\lib\tsc.js:43970:17)
    at checkClassDeclaration (C:\code\test\node_modules\typescript\lib\tsc.js:43872:13)

@ghost
Copy link

ghost commented Sep 10, 2018

I think this has to do with --strictPropertyInitialization and boolean being a union -- ran into the same problem with number | null (but not with number | undefined).

@ghost ghost added the Bug A bug in TypeScript label Sep 10, 2018
@sirtrollraptor
Copy link

After encountering the same error and bisecting, 0dbad04 is the commit that caused this bug.

@jonaskello
Copy link

jonaskello commented Sep 14, 2018

I get a similar crash in tsc 3.0.3:

node_modules/typescript/lib/tsc.js:67654
                throw e;
                ^

TypeError: Cannot read property 'kind' of undefined
    at Object.parenthesizeArrayTypeMember (node_modules/typescript/lib/tsc.js:50293:24)
    at Object.createOptionalTypeNode (node_modules/typescript/lib/tsc.js:47548:24)
    at typeReferenceToTypeNode (node_modules/typescript/lib/tsc.js:26427:44)
    at typeToTypeNodeHelper (node_modules/typescript/lib/tsc.js:26238:28)
    at typeReferenceToTypeNode (node_modules/typescript/lib/tsc.js:26415:43)
    at typeToTypeNodeHelper (node_modules/typescript/lib/tsc.js:26238:28)
    at signatureToSignatureDeclarationHelper (node_modules/typescript/lib/tsc.js:26682:52)
    at createTypeNodesFromResolvedType (node_modules/typescript/lib/tsc.js:26521:43)
    at createTypeNodeFromObjectType (node_modules/typescript/lib/tsc.js:26402:35)
    at createAnonymousTypeNode (node_modules/typescript/lib/tsc.js:26357:42)

UPDATE: Seems like this is covered by #26153.

@mgol
Copy link

mgol commented Sep 20, 2018

UPDATE: Seems like this is covered by #26153.

@jonaskello I'm not sure. I still see this error in TS 3.1.0-dev.20180919 which was released today and the fix for #26153 was merged 2 days ago.

@weswigham weswigham added this to the TypeScript 3.1 milestone Sep 20, 2018
@weswigham weswigham added the Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output label Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants