Skip to content

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

Closed

Description

@magic-akari

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:

Activity

  1. li2568261 commented on Nov 30, 2018

    @li2568261

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

  2. sheetalkamat commented on Nov 30, 2018

    @sheetalkamat
    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;
  3. luvies commented on Nov 30, 2018

    @luvies

    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.

  4. tmkn commented on Nov 30, 2018

    @tmkn

    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)

  5. weswigham commented on Nov 30, 2018

    @weswigham
    Member

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

  6. weswigham commented on Nov 30, 2018

    @weswigham
    Member

    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.

  7. li2568261 commented on Dec 1, 2018

    @li2568261

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

  8. Can-Sahin commented on Dec 1, 2018

    @Can-Sahin

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

  9. favna commented on Dec 3, 2018

    @favna

    Same issue, also went from 3.1.3 to 3.2.1. I tried making the change suggested by leekk (@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)

  10. AlexAtrx commented on Dec 5, 2018

    @AlexAtrx

    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?

  11. mandarzope commented on Dec 5, 2018

    @mandarzope

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

  12. weswigham commented on Dec 5, 2018

    @weswigham
    Member

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

  13. 1 remaining item

  14. weswigham commented on Dec 6, 2018

    @weswigham
    Member

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

  15. AlexAtrx commented on Dec 6, 2018

    @AlexAtrx

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

  16. magic-akari commented on Dec 7, 2018

    @magic-akari
    ContributorAuthor

    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 typescript@3.1.6 and crashes in typescript@3.2.1.
    And typescript@next gives me the error.

  17. livthomas commented on Jan 10, 2019

    @livthomas

    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
    
  18. eugene1g commented on Jan 10, 2019

    @eugene1g

    Tomáš Livora (@livthomas) the betas work for me e.g. 3.3.0-dev.20190110

  19. davidLeonardi commented on Jan 31, 2019

    @davidLeonardi

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

  20. edsilv commented on May 2, 2019

    @edsilv

    Same issue with typescript@next 3.5.0-dev.

  21. weswigham commented on May 2, 2019

    @weswigham
    Member

    Do you have a small repro?

  22. edsilv commented on May 2, 2019

    @edsilv

    Wesley Wigham (@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...

  23. weswigham commented on May 3, 2019

    @weswigham
    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

  24. edsilv commented on May 3, 2019

    @edsilv
  25. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions