Skip to content
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

Compilation issues with Typescript v3.8.2 & xstate v4.6.7 #1015

Closed
Khaled-Ch opened this issue Feb 21, 2020 · 24 comments
Closed

Compilation issues with Typescript v3.8.2 & xstate v4.6.7 #1015

Khaled-Ch opened this issue Feb 21, 2020 · 24 comments

Comments

@Khaled-Ch
Copy link

Khaled-Ch commented Feb 21, 2020

I am using xstate version 4.6.7 and typescript version 3.8.2.
I am having the following issue during the compilation process of my project.

node_modules/xstate/lib/interpreter.d.ts:17:22 - error TS2589: Type instantiation is excessively deep and possibly infinite.

export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = any> implements Actor<State<TContext, TEvent>, TEvent>

@Khaled-Ch Khaled-Ch added the bug label Feb 21, 2020
@davidkpiano
Copy link
Member

Is it possible to upgrade XState?

@Khaled-Ch
Copy link
Author

typescript v3.8.2
xstate v4.7.8
Still same error.

@davidkpiano
Copy link
Member

It's difficult to know what the issue is without seeing a reproducible code example, please

@Khaled-Ch
Copy link
Author

Khaled-Ch commented Feb 21, 2020

Dependencies in package.json file:

"dependencies": {
"typescript": "^3.8.2",
"xstate": "^4.7.8"
}

tsconfig.ts file:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2016",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./src"
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

The error leads to this line 17 in interpreter.d.ts

export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = any> implements Actor<State<TContext, TEvent>, TEvent> {

@Andarist
Copy link
Member

This is not a repro case though - to investigate we need to have a runnable, complete, repro case

@kpollich
Copy link

Hi all! I'm running into the same TypeScript compilation error as @Khaled-Ch.

Here's my dependency versions per package.json

"@xstate/react": "^0.8.1",
"antd": "^4.0.0-rc.5",
"next": "^9.2.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"styled-components": "^5.0.1",
"xstate": "^4.7.8"

I've pushed this up to a CodeSandbox, but I haven't used their server-side templates much. Hopefully it's functional for everyone!

https://codesandbox.io/s/github/kpollich/hangman

I've also pushed the code up to GitHub here: https://codesandbox.io/s/github/kpollich/hangman

The actual error output looks like this, and comes up during Next's TypeScript compilation I think:

69:25 Type instantiation is excessively deep and possibly infinite.
    67 |
    68 | const HomePage: NextPage = () => {
  > 69 |   const [state, send] = useMachine(gameMachine);
       |                         ^
    70 |
    71 |   return (
    72 |     <PageWrapper>
undefined

I've only just started playing with xstate today, so I apologize if I'm making a beginner mistake here. Please let me know if there's any other information or context I can provide!

Riron added a commit to MTES-MCT/trackdechets that referenced this issue Feb 24, 2020
Bug with xstate currently on newer versions
Follow on statelyai/xstate#1015
Riron added a commit to MTES-MCT/trackdechets that referenced this issue Feb 24, 2020
Bug with xstate currently on newer versions
Follow on statelyai/xstate#1015
@davidkpiano
Copy link
Member

@kpollich @Khaled-Ch Can you please try with @xstate/react@next?

@Khaled-Ch
Copy link
Author

Khaled-Ch commented Feb 24, 2020

For me solved by adding this to my tsconfig.json
"skipLibCheck": true
and used latest version from typescript and xstate as well
Now able to compile without any problems

@kpollich
Copy link

@davidkpiano Updating to @xstate/react@next fixed my issues. Thank you!

@davidalekna
Copy link

davidalekna commented Feb 26, 2020

I'm also getting this error and updating to "@xstate/react": "^1.0.0-rc.3" doesn't solve my issue. I'm working with a component lib and when compiling with tsc this is being thrown when using ts v3.8.2.

Update -->

I can confirm that updating both @xstate/react@next and xstate@next solved the problem for me.

@adamkl
Copy link

adamkl commented Feb 27, 2020

@davidalekna Just an FYI, xstate@next, as per npm, refers to 4.7.0-rc6 from 4 months ago. So I think you fixed the problem by downgrading xstate.

I'm running @xstate/react@^1.0.0-rc.3 and xstate@^4.7.8 and still seeing the issue.

skipLibCheck in my tsconfig.json didn't seem to help either.

@adamkl
Copy link

adamkl commented Feb 27, 2020

A follow up; downgrading from typescript@3.8.2 to typescript@3.7.5 got me up and running again for now.

@RomainLanz
Copy link

RomainLanz commented Feb 28, 2020

Hey all 👋

I have the same issue with xstate & @xstate/vue. The error occurs after upgrading to typescript 3.8.2.

The exact error is:

ERROR in /Users/romainlanz/workspace/xxx/node_modules/xstate/lib/interpreter.d.ts(17,22):
17:22 Type instantiation is excessively deep and possibly infinite.
    15 |     sync?: boolean;
    16 | }
  > 17 | export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObjec
t = EventObject, TTypestate extends Typestate<TContext> = any> implements Actor<State<TContext, TEvent>, TEvent> {
       |                      ^
    18 |     machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
    19 |     /**
    20 |      * The default interpreter options:
Version: typescript 3.8.2

It seems to be an issue with TypeScript itself? microsoft/TypeScript#34933

@CodingDive
Copy link
Contributor

CodingDive commented Feb 29, 2020

I also got the Type instantiation is excessively deep and possibly infinite error upon calling state.matches. It was working for a while with TypeScript 3.8.2 and I got the error out of the blue.
I saw that my global typescript installation was still on an older version (you can check with npm list -g --depth=0) and upgraded my app to TypeScript 3.8.3. I now no longer see the error which makes me think that they've either already fixed it or it's some sort of caching issue. 🤔

"xstate": "4.7.8"
"@xstate/react": "0.8.1",
"typescript": "^3.8.3"

Edit: Nevermind, no error was thrown only on the first compilation. Got the same error when making changes in watch mode. Going to downgrade TypeScript now 😬

@hyusetiawan
Copy link

I am having the same problem as well, tried: skiplibcheck and update to @next version. Still not working, I am hesitant to downgrade the typescript, any other workaround I've missed until it's fully fixed?

@lozandier
Copy link

lozandier commented Mar 11, 2020

Tried a simple state machine from the Intro to Xstate Egghead.io course as a sanity check

import {Machine} from 'xstate';


export const stopLightMachine = Machine({
  id: 'stopLight',
  initial: 'red',
  states: {
    red: {
      after: { 4000: 'yellow' },
    },
    yellow: {
      after: { 1000: 'green' },
    },
    green: {
      after: { 3000: 'red' },
    },
  },
});

Tried hooking it up in the middle of creating a simple demo of it working or not only to get the error TS2589: Type instantiation is excessively deep and possibly infinite. error using the latest version of TypeScript & XState (4.8)

import {LitElement, html, css, property, customElement, query} from 'lit-element';
import {classMap} from 'lit-html/directives/class-map';

import {stopLightMachine} from "./machines/stop-light"
import {interpret} from 'xstate'

@customElement('my-element')
class MyElement extends LitElement {

  service: any;
  state: any;
  
  static get styles() {
    return [
      css`
        p.red {
          color: red;
        }

        p.green {
          color: green;
        }


        p.yellow: {
          color: yellow;
        }
      `
    ];
  }
  
  
  connectedCallback(){
    super.connectedCallback()
    console.log('Yoooo')
    
  // Error occurs
    this.service = interpret(stopLightMachine).start()
    
    
  }
  
  render() {
    return html`<p class=${classMap({red: true, green: true, yellow: true})}>???</p>`
  }
   
}

The TSConfig used

{
  "compilerOptions": {
    "target": "es2017",
    "module": "es2015",
    "moduleResolution": "node",
    "lib": ["es2017", "dom"],
    "declaration": true,
    "sourceMap": true,
    "inlineSources": true,
    "strict": false,
    "outDir": "./",
    "skipLibCheck": true,
    "noImplicitAny": true,
    "experimentalDecorators": true,
     "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true
   
  },
"include": [
    "**/*"
],
"exclude": [
    "node_modules"
]
}

@davidkpiano Example glitch this occurs (Node 8 & 12 was used): https://glitch.com/edit/#!/abundant-outrageous-neighborhood?path=my-element.ts:36:54

@RomainLanz
Copy link

It's a known issue in TypeScript @lozandier.

You need to downgrade your version to make it work for the moment.

@lozandier
Copy link

lozandier commented Mar 11, 2020

@RomainLanz Tried downgrading all the way to TypeScript 3.5 w/ no luck

Update: Using <script>window.process = { env: 'development' }</script> allowed things to work again strangely enough after I stopped trying to downgrade

@gunn4r
Copy link

gunn4r commented Mar 28, 2020

I'm getting this same issue with:

 "@xstate/react": "0.8.1",
    "xstate": "4.8.0",
    "typescript": "3.7.5"
Error in node_modules/xstate/lib/interpreter.d.ts(17,22):
TS2589: Type instantiation is excessively deep and possibly infinite.

This was referenced Apr 4, 2020
@dhmacs
Copy link

dhmacs commented Apr 15, 2020

Same issue here 👋

  • xstate 4.8.0
  • @xstate/react 0.8.1
  • typescript 3.7.5 and 3.8.3

@davidkpiano
Copy link
Member

Please try xstate@latest (4.9.0) with the latest TypeScript. This should be fixed now.

@RomainLanz
Copy link

I confirm this is fixed on my application! Thanks! 🎉

@davidkpiano
Copy link
Member

@RomainLanz Thanks for confirming!!

@gunn4r
Copy link

gunn4r commented May 6, 2020

Can confirm fixed on mine as well. Thanks!

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

No branches or pull requests