Typescript: Poor error message when names conflict

Created on 3 Jul 2019  路  6Comments  路  Source: microsoft/TypeScript


TypeScript Version: 3.5.2


Search Terms: debug failure unexpected node error message exception

Obviously the following code is incorrect, however I would expect a friendly error message directing the user to the problem, rather than the nasty/ambiguous error message聽that is currently given: Error: Debug Failure. Unexpected node.

I ran into this in a large codebase and it took me awhile to find source of the problem.

Code

yarn add @types/lodash
import * as pick from 'lodash/pick';

export const pick = () => pick();
$ tsc

/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:73748
                throw e;
                ^

Error: Debug Failure. Unexpected node.
Node 156 was unexpected.
    at getDeclarationSpaces (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:46074:41)
    at /Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:46066:84
    at Object.forEach (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:217:30)
    at getDeclarationSpaces (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:46066:28)
    at checkExportsOnMergedDeclarations (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:46009:41)
    at checkVariableLikeDeclaration (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:47011:17)
    at checkVariableDeclaration (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:47048:20)
    at checkSourceElementWorker (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:48787:28)
    at checkSourceElement (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:48648:17)
    at Object.forEach (/Users/oliverjash/Development/typescript-playground/node_modules/typescript/lib/tsc.js:217:30)
Bug Crash

Most helpful comment

Error: Debug Failure. Unexpected node

馃悶
That's not a normal error message. The compiler actually crashed. It's 100% a bug. :smile:

All 6 comments

Error: Debug Failure. Unexpected node

馃悶
That's not a normal error message. The compiler actually crashed. It's 100% a bug. :smile:

What version of lodash is this?

repros with @types/[email protected]. The unexpected node kind is MethodSignature, which probably has something to do with following an alias along until the original pick method is encountered.

Starting failing this way in 2.6.

I have same error:
ERROR in [internal] INTERNAL ERROR: Debug Failure. Unexpected node. Node Identifier was unexpected. stack trace: Error: Debug Failure. Unexpected node. Node Identifier was unexpected. at getDeclarationSpaces (app\node_modules\type script\lib\typescript.js:59394:41) at checkExportsOnMergedDeclarations (app\node_ modules\typescript\lib\typescript.js:59320:41) at checkVariableLikeDeclaration (app\node_modu les\typescript\lib\typescript.js:60568:17) at checkVariableDeclaration (app\node_modules\ typescript\lib\typescript.js:60606:20) at checkSourceElementWorker (app\node_modules\ typescript\lib\typescript.js:63058:28) at checkSourceElement (app\node_modules\typesc ript\lib\typescript.js:62912:17) at Object.forEach (app\node_modules\typescript \lib\typescript.js:309:30) at checkVariableStatement (app\node_modules\ty pescript\lib\typescript.js:60616:16) at checkSourceElementWorker (app\node_modules\ typescript\lib\typescript.js:63027:28) at checkSourceElement (app\node_modules\typesc ript\lib\typescript.js:62912:17)

after migration from 3.5.3 to 3.7.4.
And I have no clue which package triggers this error, because project is big

@sandersn I think I've figured out why this error happens, at least in my code.
My code:

/**
 * @typedef (Object) CustomProps
 * @property (Boolean) visible
 * @property (children:React.ReactNode) children
 *
 * @param {CustomProps} props
 */
const SomeComponent=(props)=><div>Hello</div>;

As you see, there is invalid JSDoc syntax.
TS compiler crashed here typescript\lib\typescript.js:59394.

// d.kind = 75, SyntaxKind.Identifier
return ts.Debug.failBadSyntaxKind(d)

After JSDoc code was fixed, the error is gone.
I hope it will help.

Was this page helpful?
0 / 5 - 0 ratings