TypeScript: TypeError: Cannot read property 'valueDeclaration' of undefined

TypeScript Version: 3.8.0-dev.20191101

Running into this exception when trying to create declarations from .js files. Cannot use the Playground to illustrate this; it doesn’t support .d.ts generation

Using tsconfig.json:

  {
    "compilerOptions": {
      "allowJs": true,
      "checkJs": true,
      "declaration": true,
      "emitDeclarationOnly": true
    },
    "include": ["foo.js"]
  }

Run tsc, which should create foo.d.ts. Run it again to get the error.

Expected behavior:

a different error about refusing to overwrite .d.ts files

Actual behavior:

$ tsc
/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:78600
                throw e;
                ^

TypeError: Cannot read property 'valueDeclaration' of undefined
    at getExpandoSymbol (/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:28794:31)
    at getTypeReferenceType (/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:35293:22)
    at getTypeFromJSDocValueReference (/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:35332:32)
    at getTypeReferenceType (/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:35307:33)
    at resolveImportSymbolType (/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:36697:24)
    at getTypeFromImportTypeNode (/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:36672:42)
    at getTypeFromTypeNode (/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:37005:28)
    at getTypeFromTypeNode (/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:36982:28)
    at getDeclaredTypeOfTypeAlias (/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:33085:39)
    at tryGetDeclaredTypeOfSymbol (/Users/boneskull/projects/boneskull/sync-monorepo-packages/node_modules/typescript/lib/tsc.js:33216:24)

This may or may not have anything to do with the fact I’m only generating declarations from .js files.

About this issue

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

Commits related to this issue

Most upvoted comments

Has this been fixed? Im still getting the error testing against v3.8.0-dev.20191205

Here is my stack trace (the first one is react-styleguidist)

Trace
    at withContext (node_modules/typescript/lib/typescript.js:36361:25)
    at Object.typeToTypeNode (node_modules/typescript/lib/typescript.js:36316:28)
    at typeToString (node_modules/typescript/lib/typescript.js:36283:40)
    at Object.typeToString (node_modules/typescript/lib/typescript.js:33355:24)
    at Parser.getDocgenType (node_modules/react-docgen-typescript/lib/parser.js:284:43)
    at node_modules/react-docgen-typescript/lib/parser.js:331:29
    at Array.forEach (<anonymous>)
    at Parser.getPropsInfo (node_modules/react-docgen-typescript/lib/parser.js:309:27)
    at Parser.getComponentInfo (node_modules/react-docgen-typescript/lib/parser.js:129:30)
    at node_modules/react-docgen-typescript/lib/parser.js:702:27
    at Array.map (<anonymous>)
    at node_modules/react-docgen-typescript/lib/parser.js:701:14
    at Array.reduce (<anonymous>)
    at parseWithProgramProvider (node_modules/react-docgen-typescript/lib/parser.js:694:10)
    at parse (node_modules/react-docgen-typescript/lib/parser.js:71:20)
    at Object.module.exports (node_modules/react-styleguidist/lib/loaders/props-loader.js:41:12)
 FAIL  Failed to compile

[internal]
INTERNAL ERROR: Cannot read property 'valueDeclaration' of undefined
stack trace:
TypeError: Cannot read property 'valueDeclaration' of undefined
    at getBaseConstructorTypeOfClass (node_modules/typescript/lib/typescript.js:40026:40)
    at serializeAsClass (node_modules/typescript/lib/typescript.js:38036:42)
    at serializeSymbolWorker (node_modules/typescript/lib/typescript.js:37770:29)
    at serializeSymbol (node_modules/typescript/lib/typescript.js:37711:38)
    at node_modules/typescript/lib/typescript.js:37686:25
    at Map.forEach (<anonymous>)
    at visitSymbolTable (node_modules/typescript/lib/typescript.js:37685:33)
    at symbolTableToDeclarationStatements (node_modules/typescript/lib/typescript.js:37556:17)
    at node_modules/typescript/lib/typescript.js:36340:106
    at withContext (node_modules/typescript/lib/typescript.js:36362:37)
error Command failed with exit code 1.

I just rolled back to the version 3.6.4: No errors with the same code.

Hey @RyanCavanaugh, you have critical production bug here in your compiler!

Any update on this? I’m getting the error with the same stracktrace as @jasonwilliams, but unfortunately cannot narrow it down and make a repro as my project is pretty large and stack doesn’t help at all.

I’m seeing the same stacktrace as @jasonwilliams

    TypeError: Cannot read property 'valueDeclaration' of undefined
        at getBaseConstructorTypeOfClass (/home/arian/git/main/frontend/node_modules/typescript/lib/typescript.js:40038:40)
        at serializeAsClass (/home/arian/git/main/frontend/node_modules/typescript/lib/typescript.js:38042:42)
        at serializeSymbolWorker (/home/arian/git/main/frontend/node_modules/typescript/lib/typescript.js:37776:29)
        at serializeSymbol (/home/arian/git/main/frontend/node_modules/typescript/lib/typescript.js:37717:38)
        at /home/arian/git/main/frontend/node_modules/typescript/lib/typescript.js:37699:29
        at Map.forEach (<anonymous>)
        at visitSymbolTable (/home/arian/git/main/frontend/node_modules/typescript/lib/typescript.js:37698:42)
        at symbolTableToDeclarationStatements (/home/arian/git/main/frontend/node_modules/typescript/lib/typescript.js:37562:17)
        at /home/arian/git/main/frontend/node_modules/typescript/lib/typescript.js:36347:106
        at withContext (/home/arian/git/main/frontend/node_modules/typescript/lib/typescript.js:36368:37)

Version: typescript 3.8.0-dev.20191207

I have created a minimal example to reproduce the issue in OpenLayers.

See https://gist.github.com/ahocevar/b3e58e7eac7750faa235ef66bdb559ab.

The problem appears to be related to the getTypeOfSymbol() call in the getTypeFromJSDocValueReference() function. In the above example, the return type of PointFoo’s getType() method is not found, and getTypeOfSymbol() returns an errorType.

I’ve also seen this issue when upgrading to TypeScript 3.7.2 (3.6.4 works fine)

I’ve narrowed it down so that I can only see the error (Cannot read property 'valueDeclaration' of undefined) when type annotations like the following are included:

  /**
   * @param {InstanceType<import('../../utils/templateUtils')['HasNoCostError']>} error
   */
  constructor(error) {

This is the syntax I currently use to annotate that a parameter is an instance of a class which is definied in a separate .js file. I also talk about this here: https://github.com/microsoft/TypeScript/issues/29485#issuecomment-518316889

I’ve created a small gist which should reproduce the problem: https://gist.github.com/lukehesluke/8ef8e7061c6533e208e055aedb4e31b1

Keen to see how this develops and happy to help if that’s useful

@ahocevar Thanks for that! – I went through minimizing the “far cry” example above, which took almost the same time as getting through a far cry game, and got something manageable. The problem is when using an import in a jsdoc as you have in index.js.

I checked that it’s fixed now, but it’ll still be interesting to look at since it’s slightly different.

Same is happening for us, the stacktrace only includes typescript files so i don’t know what’s causing it 😦

I tried on 3.8.0-dev.20191105 and it was still the same

I have the same issue. 😦

I have no ts files in my repository, and only a couple that use jsdocs to import jsdoc typedefs and none of them use imports like @lukehesluke

Any advice for tracking down the offending file?

Building project '/home/name/projectName/tsconfig.json'...

/usr/local/lib/node_modules/typescript/lib/tsc.js:78566
                throw e;
                ^

TypeError: Cannot read property 'valueDeclaration' of undefined
    at getBaseConstructorTypeOfClass (/usr/local/lib/node_modules/typescript/lib/tsc.js:32851:40)
    at serializeAsClass (/usr/local/lib/node_modules/typescript/lib/tsc.js:31138:42)
    at serializeSymbolWorker (/usr/local/lib/node_modules/typescript/lib/tsc.js:30937:29)
    at serializeSymbol (/usr/local/lib/node_modules/typescript/lib/tsc.js:30894:38)
    at /usr/local/lib/node_modules/typescript/lib/tsc.js:30879:29
    at Map.forEach (<anonymous>)
    at visitSymbolTable (/usr/local/lib/node_modules/typescript/lib/tsc.js:30878:42)
    at symbolTableToDeclarationStatements (/usr/local/lib/node_modules/typescript/lib/tsc.js:30766:17)
    at /usr/local/lib/node_modules/typescript/lib/tsc.js:29639:106
    at withContext (/usr/local/lib/node_modules/typescript/lib/tsc.js:29659:37)

I was having this same issue with the new Typescript 3.7.2. The problem was the import below that’s importing a const instead of a type.

Component.jsx

/** @typedef {import('app/utils/validations').INVALID_FILE} INVALID_FILE */

app/utils/validations.js

export const INVALID_FILE = 'INVALID_FILE';