Skip to content

undefined errors on compile due to typedef comments #19081

@atishpatel

Description

@atishpatel

TypeScript Version: 2.5.3

Error
With tsc:

TypeError: Cannot read property '283' of undefined
    at getDeclarationSpaces (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:33121:54)
    at checkExportsOnMergedDeclarations (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:33067:41)
    at checkVariableLikeDeclaration (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:33889:17)
    at checkVariableDeclaration (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:33918:20)
    at checkSourceElement (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:35493:28)
    at Object.forEach (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:275:30)
    at checkVariableStatement (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:33926:16)
    at checkSourceElement (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:35462:28)
    at Object.forEach (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:275:30)
    at checkSourceFileWorker (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:35566:20)
    at checkSourceFile (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:35551:13)
    at Object.forEach (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:275:30)
    at getDiagnosticsWorker (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:35616:16)
    at getDiagnostics (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:35593:24)
    at Object.getEmitResolver (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:18585:13)
    at emitWorker (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:56112:69)
    at /Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:56088:66
    at runWithCancellationToken (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:56166:24)
    at Object.emit (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:56088:20)
    at compileProgram (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:59134:38)
    at compile (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:59088:26)
    at performCompilation (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:58977:33)
    at Object.executeCommandLine (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:58920:9)
    at Object.<anonymous> (/Users/atish/.config/yarn/global/node_modules/typescript/lib/tsc.js:59278:4)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/atish/.config/yarn/global/node_modules/typescript/bin/tsc:2:1)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:201:16)
    at bootstrap_node.js:626:3

With gulp-typescript:

TypeError: Cannot read property 'end' of undefined
    at getFullWidth (/Users/atish/Development/go/src/github.com/atishpatel/Gigamunch-Backend/node_modules/typescript/lib/typescript.js:6840:20)
    at Object.declarationNameToString (/Users/atish/Development/go/src/github.com/atishpatel/Gigamunch-Backend/node_modules/typescript/lib/typescript.js:7190:16)
    at checkExportsOnMergedDeclarations (/Users/atish/Development/go/src/github.com/atishpatel/Gigamunch-Backend/node_modules/typescript/lib/typescript.js:43902:138)
    at checkVariableLikeDeclaration (/Users/atish/Development/go/src/github.com/atishpatel/Gigamunch-Backend/node_modules/typescript/lib/typescript.js:44906:17)
    at checkVariableDeclaration (/Users/atish/Development/go/src/github.com/atishpatel/Gigamunch-Backend/node_modules/typescript/lib/typescript.js:44936:20)
    at checkSourceElement (/Users/atish/Development/go/src/github.com/atishpatel/Gigamunch-Backend/node_modules/typescript/lib/typescript.js:46777:28)
    at Object.forEach (/Users/atish/Development/go/src/github.com/atishpatel/Gigamunch-Backend/node_modules/typescript/lib/typescript.js:1506:30)
    at checkVariableStatement (/Users/atish/Development/go/src/github.com/atishpatel/Gigamunch-Backend/node_modules/typescript/lib/typescript.js:44945:16)
    at checkSourceElement (/Users/atish/Development/go/src/github.com/atishpatel/Gigamunch-Backend/node_modules/typescript/lib/typescript.js:46746:28)
    at Object.forEach (/Users/atish/Development/go/src/github.com/atishpatel/Gigamunch-Backend/node_modules/typescript/lib/typescript.js:1506:30)

Code
I narrowed down the error was caused by these lines of code:
file path: node_modules/@webcomponents/shadycss/src/custom-style-interface.js

/**
 * @typedef {HTMLStyleElement | {getStyle: function():HTMLStyleElement}}
 */
export let CustomStyleProvider;
...
/** @typedef {{
 * customStyles: !Array<!CustomStyleProvider>,
 * addCustomStyle: function(!CustomStyleProvider),
 * getStyleForCustomStyle: function(!CustomStyleProvider): HTMLStyleElement,
 * findStyles: function(),
 * transformCallback: ?function(!HTMLStyleElement),
 * validateCallback: ?function()
 * }}
 */
export let CustomStyleInterfaceInterface;

When I removed the comment with the typedef, everything compiled fine with both tsc and gulp-typescript.

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.

run tsc src/app-shell.ts --allowJs
app.zip

Expected behavior:
Compiles without issues even with the comment.

Actual behavior:
Doesn't. 🙃 But, it does work when the lines are deleted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged 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