Skip to content

[BUG] Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isJsonSourceFile'. #28762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
magic-akari opened this issue Nov 30, 2018 · 24 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@magic-akari
Copy link
Contributor

TypeScript Version: 3.2.1

Search Terms:

Code

declare global {
  const React: typeof import("react");
  const ReactDOM: typeof import("react-dom");
}

export {};

Expected behavior:

Actual behavior:

> tsc

/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:71026
                throw e;
                ^

Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isJsonSourceFile'.
    at Object.cast (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:1158:22)
    at getTypeOfVariableOrParameterOrPropertyWorker (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:29354:41)
    at getTypeOfVariableOrParameterOrProperty (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:29334:48)
    at getTypeOfSymbol (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:29603:24)
    at resolveImportSymbolType (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:33159:45)
    at getTypeFromImportTypeNode (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:33141:25)
    at getTypeFromTypeNode (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:33460:28)
    at checkImportType (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:43996:13)
    at checkSourceElement (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:46921:28)

Playground Link:
https://gist.github.com/magic-akari/aa10dfb809268eb4f63d5749d113a93a

Related Issues:

@li2568261
Copy link

had a similar issue.wait......

@sheetalkamat sheetalkamat added the Bug A bug in TypeScript label Nov 30, 2018
@sheetalkamat
Copy link
Member

Seems like we are doing something wrong when getting import type for module

// global.d.ts
declare global {
  const React: typeof import("./module");
}
export {};

// module.d.ts
export as namespace ReactDOM;
export function foo(): string;

@luvies
Copy link

luvies commented Nov 30, 2018

I got this issue while using webpack's dev server (in a project based on create-react-app). It will compile fine initially, but it will then throw this error whenever it attempts to re-compile.

@tmkn
Copy link

tmkn commented Nov 30, 2018

I got this issue while using webpack's dev server (in a project based on create-react-app). It will compile fine initially, but it will then throw this error whenever it attempts to re-compile.

Can confirm, that's my issue as well after updating to 3.2.1, although I'm using webpack standalone(no create react app)

@weswigham
Copy link
Member

This seems to be fixed in master, but not in 3.2 - will have to see by what change.

@weswigham
Copy link
Member

weswigham commented Nov 30, 2018

Ah, no, it's not fixed in master, i just had an outdated master in my laptop. Regression introduced by #27281 - now that it's resolving aliases prior to merging, a sourcefile can end up merged with a property (it used to merge with the alias declaration instead), and that should be handled.

@li2568261
Copy link

li2568261 commented Dec 1, 2018

I remove "esModuleInterop": true; add "allowSyntheticDefaultImports": true.solved the problem.

@Can-Sahin
Copy link

Same issue here. The only change I made to a repository is to update 3.1.3 to 3.2.1.

@favna
Copy link

favna commented Dec 3, 2018

Same issue, also went from 3.1.3 to 3.2.1. I tried making the change suggested by @li2568261, however our project requires esModuleInterop to build at all.

(It's a React Redux frontend building with babel-loader, awesome-typescript-loader and through webpack)

@alatras
Copy link

alatras commented Dec 5, 2018

I have the same error with different cause (I guess):

yarn start v0.17.8
$ ts-node ./src/engine/server/server 

/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:1325
        return Debug.fail("Invalid cast. The supplied value " + value + " did not pass the test '" + Debug.getFunctionName(test) + "'.");
                     ^
Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isJsonSourceFile'.
    at Object.cast (/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:1325:22)
    at getTypeOfVariableOrParameterOrPropertyWorker (/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:35591:41)
    at getTypeOfVariableOrParameterOrProperty (/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:35567:48)
    at getTypeOfSymbol (/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:35856:24)
    at getExternalModuleMember (/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:32495:64)
    at getTargetOfImportSpecifier (/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:32530:20)
    at getTargetOfAliasDeclaration (/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:32562:28)
    at resolveAlias (/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:32595:30)
    at checkAliasSymbol (/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:55749:26)
    at checkImportBinding (/Users/aa/.nvm/versions/node/v6.10.3/lib/node_modules/typescript/lib/typescript.js:55778:13)
error Command failed with exit code 1.

Any idea?

@mandarzope
Copy link

If typescript version is locked to 3.1.6 it will remove the 'isJsonSourceFile' error

@weswigham
Copy link
Member

@A-Atrash with what version of the compiler? This fix is only in typescript@next.

@magic-akari
Copy link
Contributor Author

I have installed typescript@next and get the error

global.d.ts:2:9 - error TS2502: 'React' is referenced directly or indirectly in its own type annotation.

2   const React: typeof import("react");

while the ReactDOM works as expected.

Any idea?

@weswigham
Copy link
Member

Does something in the react module somehow depend on the global declaration you add? Offhandedly, that's what I can think of.

@alatras
Copy link

alatras commented Dec 6, 2018

@weswigham I solved it by downgrading to TypeScript 3.1 (if this makes sense!)

@magic-akari
Copy link
Contributor Author

magic-akari commented Dec 7, 2018

Does something in the react module somehow depend on the global declaration you add? Offhandedly, that's what I can think of.

I have no idea. I never modified @types/react or other libs, The gist will reproduce the error with typescript@next.

I am going to export the types of React as global Object, for I import React in html's script tag via CDN.
The gist works fine in [email protected] and crashes in [email protected].
And typescript@next gives me the error.

@livthomas
Copy link

I am still getting the same error in TypeScript 3.2.2 where it should have been fixed.

ERROR in : Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isJsonSourceFile'.
    at Object.cast (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:1325:22)
    at getTypeOfVariableOrParameterOrPropertyWorker (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:35591:41)
    at getTypeOfVariableOrParameterOrProperty (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:35567:48)
    at getTypeOfSymbol (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:35856:24)
    at checkVariableLikeDeclaration (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:54043:41)
    at checkVariableDeclaration (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:54116:20)
    at checkSourceElement (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56137:28)
    at Object.forEach (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:210:30)
    at checkVariableStatement (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:54126:16)
    at checkSourceElement (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56106:28)
    at Object.forEach (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:210:30)
    at checkSourceFileWorker (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56305:20)
    at checkSourceFile (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56277:13)
    at getDiagnosticsWorker (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56352:17)
    at Object.getDiagnostics (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56338:24)
    at /home/myprofile/myproject/node_modules/typescript/lib/typescript.js:87001:85

@eugene1g
Copy link

@livthomas the betas work for me e.g. 3.3.0-dev.20190110

tianzhich pushed a commit to tianzhich/counseling-system-fe that referenced this issue Jan 14, 2019
@davidLeonardi
Copy link

Still having this issue with typescript@next ,  which is now 3.4.0-dev[31st jan 2019]

@edsilv
Copy link

edsilv commented May 2, 2019

Same issue with typescript@next 3.5.0-dev.

@weswigham
Copy link
Member

Do you have a small repro?

@edsilv
Copy link

edsilv commented May 2, 2019

@weswigham https://github.com/IIIF-Commons/iiif-metadata

I solved it by updating stencil to 0.18.0. Try setting it back to 0.16.2 to reproduce.

As far as I can tell it's the contents of globals.d.ts that are causing the build error. So not sure why updating stencil made a difference...

@weswigham
Copy link
Member

Stencil 0.16.2 uses TS 3.2.2 internally (irrespective of what version you install above it), which'd be why upgrading stencil fixed it for you :P

@edsilv
Copy link

edsilv commented May 3, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests