Typescript: TypeError: Cannot read property 'kind' of undefined at getAssignmentTargetKind

Created on 11 Jan 2019  Β·  25Comments  Β·  Source: microsoft/TypeScript


TypeScript Version: 3.2.2


Search Terms:
Cannot read property 'kind' of undefined

I have found some results about this error but I haven't found anything about the problem where my project throws the error: "at getAssignmentTargetKind"

Code
I'm using angular 7.2.0 - the error first occured when I updated from 6.x to 7.x.
Also I tried creating a new project and just migrate everything file by file but since the error happens so randomly it's almost impossible to track down the file causing the problem :/

Here's the full error message:

ERROR in : TypeError: Cannot read property 'kind' of undefined
    at getAssignmentTargetKind (E:\dev\client7\node_modules\typescript\lib\typescript.js:10234:28)
    at Object.isAssignmentTarget (E:\dev\client7\node_modules\typescript\lib\typescript.js:10277:16)
    at checkObjectLiteral (E:\dev\client7\node_modules\typescript\lib\typescript.js:47309:45)
    at checkExpressionWorker (E:\dev\client7\node_modules\typescript\lib\typescript.js:51806:28)
    at checkExpression (E:\dev\client7\node_modules\typescript\lib\typescript.js:51751:42)
    at checkExpressionWithContextualType (E:\dev\client7\node_modules\typescript\lib\typescript.js:51581:26)
    at checkApplicableSignature (E:\dev\client7\node_modules\typescript\lib\typescript.js:48900:35)
    at chooseOverload (E:\dev\client7\node_modules\typescript\lib\typescript.js:49219:26)
    at resolveCall (E:\dev\client7\node_modules\typescript\lib\typescript.js:49171:26)
    at resolveCallExpression (E:\dev\client7\node_modules\typescript\lib\typescript.js:49478:20)
    at resolveSignature (E:\dev\client7\node_modules\typescript\lib\typescript.js:49766:28)
    at getResolvedSignature (E:\dev\client7\node_modules\typescript\lib\typescript.js:49798:26)
    at checkCallExpression (E:\dev\client7\node_modules\typescript\lib\typescript.js:49890:29)
    at checkExpressionWorker (E:\dev\client7\node_modules\typescript\lib\typescript.js:51817:28)
    at checkExpression (E:\dev\client7\node_modules\typescript\lib\typescript.js:51751:42)
    at resolveDecorator (E:\dev\client7\node_modules\typescript\lib\typescript.js:49685:28)

I added this to typescript.js:

function getAssignmentTargetKind(node) {
        var parent = node.parent;

        if(!parent) {
          console.log(node)
        }

Here's the console.log

NodeObject {
  pos: 493,
  end: 596,
  flags: 8,
  transformFlags: 536870912,
  parent: undefined,
  kind: 188,
  properties:
   [ NodeObject {
       pos: 494,
       end: 516,
       flags: 0,
       transformFlags: 536870912,
       parent: [NodeObject],
       kind: 275,
       decorators: undefined,
       modifiers: undefined,
       name: [IdentifierObject],
       questionToken: undefined,
       exclamationToken: undefined,
       initializer: [TokenObject],
       modifierFlagsCache: 536870912,
       symbol: [SymbolObject] },
     NodeObject {
       pos: 517,
       end: 555,
       flags: 8,
       transformFlags: 536870912,
       parent: undefined,
       kind: 275,
       name: [IdentifierObject],
       questionToken: undefined,
       initializer: [NodeObject],
       original: [NodeObject],
       modifierFlagsCache: 536870912 },
     NodeObject {
       pos: -1,
       end: -1,
       flags: 8,
       transformFlags: 536870912,
       parent: undefined,
       kind: 275,
       name: [IdentifierObject],
       questionToken: undefined,
       initializer: [NodeObject],
       modifierFlagsCache: 536870912 },
     pos: -1,
     end: -1,
     hasTrailingComma: undefined,
     transformFlags: 536870912 ],
  multiLine: true,
  original:
   NodeObject {
     pos: 493,
     end: 596,
     flags: 0,
     transformFlags: 536870912,
     parent:
      NodeObject {
        pos: 483,
        end: 597,
        flags: 8192,
        transformFlags: 536870912,
        parent: [NodeObject],
        kind: 191,
        expression: [IdentifierObject],
        arguments: [Array],
        id: 136557 },
     kind: 188,
     multiLine: true,
     properties:
      [ [NodeObject],
        [NodeObject],
        [NodeObject],
        pos: 494,
        end: 594,
        transformFlags: 536870912 ],
     symbol:
      SymbolObject {
        flags: 4096,
        escapedName: '__object',
        declarations: [Array],
        members: [Map],
        valueDeclaration: [Circular] },
     nextContainer:
      NodeObject {
        pos: 666,
        end: 879,
        flags: 128,
        transformFlags: 536875010,
        parent: [NodeObject],
        kind: 157,
        decorators: undefined,
        modifiers: undefined,
        typeParameters: undefined,
        parameters: [Array],
        body: [NodeObject],
        modifierFlagsCache: 536870912,
        symbol: [SymbolObject],
        locals: [Map],
        returnFlowNode: [Object],
        nextContainer: [NodeObject],
        id: 136559 },
     contextualType: undefined,
     contextualMapper: undefined,
     jsDocCache: [] },
  modifierFlagsCache: 536870912,
  contextualType:
   TypeObject {
     checker:
      { getNodeCount: [Function: getNodeCount],
        getIdentifierCount: [Function: getIdentifierCount],
        getSymbolCount: [Function: getSymbolCount],
        getTypeCount: [Function: getTypeCount],
        isUndefinedSymbol: [Function: isUndefinedSymbol],
        isArgumentsSymbol: [Function: isArgumentsSymbol],
        isUnknownSymbol: [Function: isUnknownSymbol],
        getMergedSymbol: [Function: getMergedSymbol],
        getDiagnostics: [Function: getDiagnostics],
        getGlobalDiagnostics: [Function: getGlobalDiagnostics],
        getTypeOfSymbolAtLocation: [Function: getTypeOfSymbolAtLocation],
        getSymbolsOfParameterPropertyDeclaration: [Function: getSymbolsOfParameterPropertyDeclaration],
        getDeclaredTypeOfSymbol: [Function: getDeclaredTypeOfSymbol],
        getPropertiesOfType: [Function: getPropertiesOfType],
        getPropertyOfType: [Function: getPropertyOfType],
        getTypeOfPropertyOfType: [Function: getTypeOfPropertyOfType],
        getIndexInfoOfType: [Function: getIndexInfoOfType],
        getSignaturesOfType: [Function: getSignaturesOfType],
        getIndexTypeOfType: [Function: getIndexTypeOfType],
        getBaseTypes: [Function: getBaseTypes],
        getBaseTypeOfLiteralType: [Function: getBaseTypeOfLiteralType],
        getWidenedType: [Function: getWidenedType],
        getTypeFromTypeNode: [Function: getTypeFromTypeNode],
        getParameterType: [Function: getTypeAtPosition],
        getPromisedTypeOfPromise: [Function: getPromisedTypeOfPromise],
        getReturnTypeOfSignature: [Function: getReturnTypeOfSignature],
        getNullableType: [Function: getNullableType],
        getNonNullableType: [Function: getNonNullableType],
        typeToTypeNode: [Function: typeToTypeNode],
        indexInfoToIndexSignatureDeclaration: [Function: indexInfoToIndexSignatureDeclaration],
        signatureToSignatureDeclaration: [Function: signatureToSignatureDeclaration],
        symbolToEntityName: [Function: symbolToEntityName],
        symbolToExpression: [Function: symbolToExpression],
        symbolToTypeParameterDeclarations: [Function: symbolToTypeParameterDeclarations],
        symbolToParameterDeclaration: [Function: symbolToParameterDeclaration],
        typeParameterToDeclaration: [Function: typeParameterToDeclaration],
        getSymbolsInScope: [Function: getSymbolsInScope],
        getSymbolAtLocation: [Function: getSymbolAtLocation],
        getShorthandAssignmentValueSymbol: [Function: getShorthandAssignmentValueSymbol],
        getExportSpecifierLocalTargetSymbol: [Function: getExportSpecifierLocalTargetSymbol],
        getExportSymbolOfSymbol: [Function: getExportSymbolOfSymbol],
        getTypeAtLocation: [Function: getTypeAtLocation],
        getPropertySymbolOfDestructuringAssignment: [Function: getPropertySymbolOfDestructuringAssignment],
        signatureToString: [Function: signatureToString],
        typeToString: [Function: typeToString],
        symbolToString: [Function: symbolToString],
        typePredicateToString: [Function: typePredicateToString],
        writeSignature: [Function: writeSignature],
        writeType: [Function: writeType],
        writeSymbol: [Function: writeSymbol],
        writeTypePredicate: [Function: writeTypePredicate],
        getAugmentedPropertiesOfType: [Function: getAugmentedPropertiesOfType],
        getRootSymbols: [Function: getRootSymbols],
        getContextualType: [Function: getContextualType],
        getContextualTypeForObjectLiteralElement: [Function: getContextualTypeForObjectLiteralElement],
        getContextualTypeForArgumentAtIndex: [Function: getContextualTypeForArgumentAtIndex],
        getContextualTypeForJsxAttribute: [Function: getContextualTypeForJsxAttribute],
        isContextSensitive: [Function: isContextSensitive],
        getFullyQualifiedName: [Function: getFullyQualifiedName],
        getResolvedSignature: [Function: getResolvedSignature],
        getResolvedSignatureForSignatureHelp: [Function: getResolvedSignatureForSignatureHelp],
        getConstantValue: [Function: getConstantValue],
        isValidPropertyAccess: [Function: isValidPropertyAccess],
        isValidPropertyAccessForCompletions: [Function: isValidPropertyAccessForCompletions],
        getSignatureFromDeclaration: [Function: getSignatureFromDeclaration],
        isImplementationOfOverload: [Function: isImplementationOfOverload],
        getImmediateAliasedSymbol: [Function: getImmediateAliasedSymbol],
        getAliasedSymbol: [Function: resolveAlias],
        getEmitResolver: [Function: getEmitResolver],
        getExportsOfModule: [Function: getExportsOfModuleAsArray],
        getExportsAndPropertiesOfModule: [Function: getExportsAndPropertiesOfModule],
        getSymbolWalker: [Function: getSymbolWalker],
        getAmbientModules: [Function: getAmbientModules],
        getJsxIntrinsicTagNamesAt: [Function: getJsxIntrinsicTagNamesAt],
        isOptionalParameter: [Function: isOptionalParameter],
        tryGetMemberInModuleExports: [Function: tryGetMemberInModuleExports],
        tryGetMemberInModuleExportsAndProperties: [Function: tryGetMemberInModuleExportsAndProperties],
        tryFindAmbientModuleWithoutAugmentations: [Function: tryFindAmbientModuleWithoutAugmentations],
        getApparentType: [Function: getApparentType],
        getUnionType: [Function: getUnionType],
        createAnonymousType: [Function: createAnonymousType],
        createSignature: [Function: createSignature],
        createSymbol: [Function: createSymbol],
        createIndexInfo: [Function: createIndexInfo],
        getAnyType: [Function: getAnyType],
        getStringType: [Function: getStringType],
        getNumberType: [Function: getNumberType],
        createPromiseType: [Function: createPromiseType],
        createArrayType: [Function: createArrayType],
        getElementTypeOfArrayType: [Function: getElementTypeOfArrayType],
        getBooleanType: [Function: getBooleanType],
        getFalseType: [Function: getFalseType],
        getTrueType: [Function: getTrueType],
        getVoidType: [Function: getVoidType],
        getUndefinedType: [Function: getUndefinedType],
        getNullType: [Function: getNullType],
        getESSymbolType: [Function: getESSymbolType],
        getNeverType: [Function: getNeverType],
        isSymbolAccessible: [Function: isSymbolAccessible],
        getObjectFlags: [Function: getObjectFlags],
        isArrayLikeType: [Function: isArrayLikeType],
        isTypeInvalidDueToUnionDiscriminant: [Function: isTypeInvalidDueToUnionDiscriminant],
        getAllPossiblePropertiesOfTypes: [Function: getAllPossiblePropertiesOfTypes],
        getSuggestionForNonexistentProperty: [Function: getSuggestionForNonexistentProperty],
        getSuggestionForNonexistentSymbol: [Function: getSuggestionForNonexistentSymbol],
        getSuggestionForNonexistentExport: [Function: getSuggestionForNonexistentExport],
        getBaseConstraintOfType: [Function: getBaseConstraintOfType],
        getDefaultFromTypeParameter: [Function: getDefaultFromTypeParameter],
        resolveName: [Function: resolveName],
        getJsxNamespace: [Function: getJsxNamespace],
        getAccessibleSymbolChain: [Function: getAccessibleSymbolChain],
        getTypePredicateOfSignature: [Function: getTypePredicateOfSignature],
        resolveExternalModuleSymbol: [Function: resolveExternalModuleSymbol],
        tryGetThisTypeAt: [Function: tryGetThisTypeAt],
        getTypeArgumentConstraint: [Function: getTypeArgumentConstraint],
        getSuggestionDiagnostics: [Function: getSuggestionDiagnostics],
        runWithCancellationToken: [Function: runWithCancellationToken],
        getLocalTypeParametersOfClassOrInterfaceOrTypeAlias:
         [Function: getLocalTypeParametersOfClassOrInterfaceOrTypeAlias] },
     flags: 524288,
     id: 14277,
     objectFlags: 2,
     symbol:
      SymbolObject {
        flags: 66,
        escapedName: 'Component',
        declarations: [Array],
        members: [Map],
        parent: [SymbolObject],
        exports: Map {},
        valueDeclaration: [NodeObject],
        id: 118624,
        isReferenced: 67897832 },
     members:
      Map {
        'changeDetection' => [SymbolObject],
        'viewProviders' => [SymbolObject],
        'moduleId' => [SymbolObject],
        'templateUrl' => [SymbolObject],
        'template' => [SymbolObject],
        'styleUrls' => [SymbolObject],
        'styles' => [SymbolObject],
        'animations' => [SymbolObject],
        'encapsulation' => [SymbolObject],
        'interpolation' => [SymbolObject],
        'entryComponents' => [SymbolObject],
        'preserveWhitespaces' => [SymbolObject],
        'selector' => [SymbolObject],
        'inputs' => [SymbolObject],
        'outputs' => [SymbolObject],
        'providers' => [SymbolObject],
        'exportAs' => [SymbolObject],
        'queries' => [SymbolObject],
        'host' => [SymbolObject],
        'jit' => [SymbolObject] },
     properties:
      [ [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject] ],
     callSignatures: [],
     constructSignatures: [],
     stringIndexInfo: undefined,
     numberIndexInfo: undefined,
     resolvedBaseTypes: [ [TypeObject] ],
     declaredProperties:
      [ [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject],
        [SymbolObject] ],
     declaredCallSignatures: [],
     declaredConstructSignatures: [],
     declaredStringIndexInfo: undefined,
     declaredNumberIndexInfo: undefined },
  contextualMapper: undefined }

Expected behavior:
No errors

Actual behavior:
See above

Is there anything I can do to finally track down the file/code causing the error?

External

Most helpful comment

Same issue for me. I use angular 7.2.2, typescript 3.2.4

All 25 comments

Same issue for me. I use angular 7.2.2, typescript 3.2.4

i have the same issue with 7.2.2 and 3.2.4 and with 3.1.6 .

Same issue with angular 7.2.0, typescript 3.1.6

Same issue for me as well, happens during watch mode when a linked library is rebuild. Angular: 7.2.4 Typescript: 3.2.4

Any idea ? How can we help you ?

Same issue with angular 7.2.6 and typescript 3.1.6

Don't know if is the same cause, but I'm having the same error with the following code that, although is weird, tsc is not emitting any diagnostics and it crash without stacktrace (was able to get a stacktrace with ts-node).

class C<S> {
  a={}
  m(s: S) {
    const b = { ...this.a, ...s } = {   }
  }
}
/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:71491
                throw e;
                ^

TypeError: Cannot read property 'kind' of undefined
    at Object.isIdentifier (/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:10382:21)
    at getLiteralTypeFromPropertyName (/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:32924:23)
    at Object.map (/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:378:29)
    at getRestType (/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:29004:47)
    at checkObjectLiteralDestructuringPropertyAssignment (/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:43034:28)
    at checkObjectLiteralAssignment (/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:43003:17)
    at checkDestructuringAssignment (/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:43106:24)
    at checkBinaryLikeExpression (/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:43186:24)
    at checkBinaryExpression (/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:43181:20)
    at checkExpressionWorker (/home/sg/git/jsx-alone/jsx-alone-dom-extra/node_modules/typescript/lib/tsc.js:43743:28)


My two cents, keep it up

same issue angular 7.2.7, ts 3.2.4
its so annoying....

@volser when does it happen? Could you make a repro or describe your setup in detail?

when I first time run ng serve all ok, but when I change something and hot reload compiles changes, I'm getting such error, BUT not each time, happens randomly. may be 1 of 10 reloads

and only on Windows

looks like it happens, when I'm making changes during compiling

I tried to reinstall NodeJs, visual studio code (why not). I tried ng serve on Windows cmd and Powershell.
Nothing worked

As recommended here , Installing '@types/history' package seems to have fixed it.

Still I'm interested in what's causing it

@therawk Hi, I installed '@type/history' and it dosn't works.
Personnaly, I don't understand how could it have worked.

@Provson Hmmm I just checked what the package does and as you said - it's not supposed to work/solve this problem πŸ€”
Really strange. I never had this error after installing it though

I know this might not help too much, but seeing as it's an Angular specific bug with an object literal might narrow down what's breaking somewhere.

The code for SyntaxKind: or the kind in the original post being 188 is "ObjectLiteralExpression".

From this code piece.

https://github.com/Microsoft/TypeScript/blob/master/lib/typescriptServices.d.ts

This will only help us maybe figure out why the parent is undefined from some ObjectLiteral in Angular.

Any update ?
Still present with angular 7.2.11 and typescript 3.2.4

have the exact issue with angular 7.2.10 and typescript 3.1.1 (had ts 3.2.4 before, and downgraded to 3.1.1 to see if it fixes the issue).
it happens mostly when saving something in the project and it sometimes throws this error when trying to re-compile. then i need to stop it and re-run ng serve.
it's just annoying, not a big issue (but still an issue).

Hey @volser and @yevgeni-eosos, thanks for the info! Unfortunately I'm still unable to repro πŸ˜•

Here's what I tried:

  1. Boot Windows 10 in Parallels
  2. I have node 8.12.0 on that OS
  3. npm i -g @angular/[email protected] (resolved to 7.2.4)
  4. ng new angular-test, no routing, plain CSS: installed typescript 3.2.4
  5. ng serve
  6. Open src/app/app.component.ts and make small edits. Tried maybe 50–100 times, especially changing stuff in and around the @Component decorator since the stack trace shared started with resolveDecorator.

But no crashes. If anyone can share a repo or a zip file of a codebase that exhibits the issue, that would be 🌟

Thanks!

I'm resolving this as an Angular bug (see https://github.com/angular/angular-cli/issues/13861 ) - the call stack + debug print indicate that TS was given a SourceFile where an ObjectLiteralExpression didn't have a parent, which is an impossible state for TS to put itself into. The root cause here is some other code inserting synthesized nodes into the source tree and then trying to perform top-level checker operations on the resulting object - this isn't legal to do (SourceFiles are immutable) and the checker is not equipped to handle this.

With actual repro steps we could potentially investigate further on our side to help out, but as-is this is effectively a corrupted source tree and there's no issue on the TS side.

This problem happens to me when I am working on some feature in an angular project, and I must change the branch in the repository where all the files that the other branch does not have are deleted.

I'm having the same problem. If you find a solution, I will be attentive!

I'm also having the same problem. If you find a solution, I will be attentive!

I had the same issue, but it was in my tsconfig.json.
I added the "files" key and it helps.
Below is my config file.
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist",
"target": "es2017",
"isolatedModules": false,
"noEmit": false,
"sourceMap": true
},
"files": [
"./node_modules/@types/node/index.d.ts"
],
"include": ["server/*/.ts"],
"exclude": [
"node_modules"
]
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Zlatkovsky picture Zlatkovsky  Β·  3Comments

fwanicka picture fwanicka  Β·  3Comments

DanielRosenwasser picture DanielRosenwasser  Β·  3Comments

siddjain picture siddjain  Β·  3Comments

blendsdk picture blendsdk  Β·  3Comments