Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

'Debug Failure: Unexpected Node' when using a JSDoc type with a decorator #37276

Copy link
Copy link
@refi64

Description

@refi64
Issue body actions

TypeScript Version: Nightly, 3.8.3

Search Terms: jsdoc, "unexpected node"

Expected behavior: Compilation to show an error. (I accidentally used a JSDoc type, jumping between too many different languages at once...)

Actual behavior: TypeScript crashed, from the CLI it crashed even before any diagnostics were printed:

/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:81040
                throw e;
                ^

Error: Debug Failure. Unexpected node.
Node 297 was unexpected.
    at serializeTypeNode (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64374:37)
    at serializeTypeOfNode (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64249:28)
    at addOldTypeMetadata (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64191:92)
    at addTypeMetadata (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64185:17)
    at transformAllDecoratorsOfDeclaration (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64104:13)
    at generateClassElementDecorationExpression (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64129:40)
    at generateClassElementDecorationExpressions (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64115:34)
    at addClassElementDecorationStatements (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64108:44)
    at visitClassDeclaration (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:63906:13)
    at visitTypeScript (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:63795:28)
error Command failed with exit code 1.

From the playground, the error is a bit different and a diagnostic is shown first:

Uncaught (in promise) Error: Debug Failure. Unexpected node.
Node JSDocNullableType was unexpected.
    at ae (tsWorker.js:21)
    at ne (tsWorker.js:21)
    at tsWorker.js:21
    at tsWorker.js:21
    at q (tsWorker.js:21)
    at X (tsWorker.js:21)
    at tsWorker.js:21
    at J (tsWorker.js:21)
    at tsWorker.js:21
    at F (tsWorker.js:21)

Related Issues: #27999 seems similar

Code

declare function decorator(): PropertyDecorator

class X {
    @decorator()
    foo?: string?
}

Note that this requires emitDecoratorMetadata: true and experimentalDecorators: true.

Output
"use strict";
X;
{
    foo ?  : string ?
        :
    ;
}
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

EDIT: Please ignore the title rename, I hit Enter too soon by accident...

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScript

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

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.