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

Bug: Compilation fails on TypeScript 4.8.2 #3557

Closed
irv075 opened this issue Aug 30, 2022 · 1 comment · Fixed by #3559
Closed

Bug: Compilation fails on TypeScript 4.8.2 #3557

irv075 opened this issue Aug 30, 2022 · 1 comment · Fixed by #3559

Comments

@irv075
Copy link

irv075 commented Aug 30, 2022

Description

Compilation fails when compiling with TypeScript v4.8.2

Error message:

node_modules/xstate/lib/interpreter.d.ts:181:122 - error TS2344: Type 'TChildStateSchema' does not satisfy the constraint 'StateSchema<any>'.

181     spawnMachine<TChildContext, TChildStateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: { 
                                                                                                                             ~~~~~~~~~~~~~~~~~

  node_modules/xstate/lib/interpreter.d.ts:181:33
    181     spawnMachine<TChildContext, TChildStateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: {
                                        ~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends StateSchema<any>` constraint.

node_modules/xstate/lib/types.d.ts:231:62 - error TS2344: Type 'TStateSchema["states"][K]' does not satisfy the constraint 'StateSchema<any>'.
  Type 'TStateSchema["states"][keyof TStateSchema["states"]]' is not assignable to type 'StateSchema<any>'.
    Type 'TStateSchema["states"][string] | TStateSchema["states"][number] | TStateSchema["states"][symbol]' is not assignable to type 'StateSchema<any>'.
      Type 'TStateSchema["states"][string]' is not assignable to type 'StateSchema<any>'.

231     [K in keyof TStateSchema['states']]: StateNode<TContext, TStateSchema['states'][K], TEvent>;
                                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/xstate/lib/types.d.ts:234:68 - error TS2344: Type 'TStateSchema["states"][K]' does not satisfy the constraint 'StateSchema<any>'.
  Type 'TStateSchema["states"][keyof TStateSchema["states"]]' is not assignable to type 'StateSchema<any>'.
    Type 'TStateSchema["states"][string] | TStateSchema["states"][number] | TStateSchema["states"][symbol]' is not assignable to type 'StateSchema<any>'.
      Type 'TStateSchema["states"][string]' is not assignable to type 'StateSchema<any>'.

234     [K in keyof TStateSchema['states']]: StateNodeConfig<TContext, TStateSchema['states'][K], TEvent, TAction>;
                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/xstate/lib/types.d.ts:237:72 - error TS2344: Type 'TStateSchema["states"][K]' does not satisfy the constraint 'StateSchema<any>'.
  Type 'TStateSchema["states"][keyof TStateSchema["states"]]' is not assignable to type 'StateSchema<any>'.
    Type 'TStateSchema["states"][string] | TStateSchema["states"][number] | TStateSchema["states"][symbol]' is not assignable to type 'StateSchema<any>'.
      Type 'TStateSchema["states"][string]' is not assignable to type 'StateSchema<any>'.

237     [K in keyof TStateSchema['states']]: StateNodeDefinition<TContext, TStateSchema['states'][K], TEvent>;
                                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~


Found 4 errors in 2 files.

Errors  Files
     1  node_modules/xstate/lib/interpreter.d.ts:181
     3  node_modules/xstate/lib/types.d.ts:231

Expected result

Application complies without error

Actual result

Compilation fails with the error noted above

Reproduction

Need to run tsc to see error

Additional context

Tried xstate 4.32.1 and 4.33.2, same result. This is our tsconfig:

{
  "compilerOptions": {
    "incremental": true,
    "target": "ES2021",
    "moduleResolution": "node",
    "module": "commonjs",
    "noLib": false,
    "declaration": true,
    "inlineSourceMap": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "traceResolution": false,
    "listEmittedFiles": false,
    "listFiles": false,
    "pretty": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "lib": [
      "ES7",
      "ES2021",
      "dom"
    ]
  },
  "exclude": [
    "node_modules/**"
  ],
  "compileOnSave": false
}
@Andarist
Copy link
Member

I've created a PR to fix this in XState: #3559 . However, in the process, I've discovered a bug in TS that prevents me from applying a better fix (in my eyes). I've even managed to fix the said bug: microsoft/TypeScript#50540 so let's wait a couple of days to see what happens with this PR.

In the meantime, you should be able to use skipLibCheck: true in your tsconfig.json to work around this issue.

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

Successfully merging a pull request may close this issue.

3 participants