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:
had a similar issue.wait......
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;
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.
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)
This seems to be fixed in master
, but not in 3.2
- will have to see by what change.
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.
I remove "esModuleInterop": true
; add "allowSyntheticDefaultImports": true
.solved the problem.
Same issue here. The only change I made to a repository is to update 3.1.3 to 3.2.1.
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)
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?
If typescript version is locked to 3.1.6 it will remove the 'isJsonSourceFile' error
@A-Atrash with what version of the compiler? This fix is only in typescript@next
.
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?
Does something in the react module somehow depend on the global declaration you add? Offhandedly, that's what I can think of.
@weswigham I solved it by downgrading to TypeScript 3.1 (if this makes sense!)
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.
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
@livthomas the betas work for me e.g. 3.3.0-dev.20190110
Still having this issue with typescript@next , Β which is now 3.4.0-dev[31st jan 2019]
Same issue with typescript@next 3.5.0-dev
.
Do you have a small repro?
@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...
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
Right... Makes sense!
On Fri, 3 May 2019, 04:42 Wesley Wigham, notifications@github.com wrote:
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β
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/TypeScript/issues/28762#issuecomment-488917329,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAKFY6IYAE5DL425C6PACH3PTOYD7ANCNFSM4GHNZYHQ
.
Most helpful comment
I remove
"esModuleInterop": true
; add"allowSyntheticDefaultImports": true
.solved the problem.