Xstate: [4.7.0] Property 'observable' does not exist on type 'SymbolConstructor'.

Created on 30 Nov 2019  路  9Comments  路  Source: davidkpiano/xstate

Description

TypeScript is throwing an error as of [email protected].

Expected Result

No errors.

Actual Result

node_modules/xstate/lib/interpreter.d.ts(171,13): Error TS2339: Property 'observable' does not exist on type 'SymbolConstructor'.

Reproduction

The default reproduction example includes the problem, but you have to download it from CodeSandbox and run tsc locally to see it, as far as I know.

Additional context

xstate v4.6.7 is OK, but v4.7.0 and v4.7.1 (at the time of this writing) exhibit the error.

bug

All 9 comments

When building locally, if you change this in packages/core/src/interpreter.ts:1216, does it fix the problem?

- public [Symbol.observable]() {
+ public [(Symbol as any).observable]() {
    return this;
  }

Yes, it appears so. Rebuilding after making that change completely removes the offending line from the built types (packages/core/lib/interpreter.d.ts:171):

    toJSON(): {
        id: string;
    };
-   [Symbol.observable](): this;
}
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): Interpreter<TC, any, TE>;
export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): Actor;

That's fine; that line is for run-time compatibility with TC39 observables anyway.

That's fine; that line is for run-time compatibility with TC39 observables anyway.

I don't think this is fine. Creating an empty TypeScript project with xstate doesn't compile so basically the whole package in NPM is broken for TypeScript users:

package.json:

{
  "name": "xstate-test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "xstate": "^4.7.1"
  },
  "devDependencies": {
    "typescript": "^3.7.2"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "lib": [
      "dom",
      "es2015"
    ]
  },
  "include": [
    "test.ts"
  ]
}

test.ts:

import * as xstate from 'xstate';

Trying to compile this project with tsc gives the error mentioned in the issue title.

@qtiki The fix hasn't made it into a published version, yet.

Oh I thought you were discussing a local workaround and not a fix to the package. I'll revert to an older version then while waiting for the fix. Thanks.

You can patch it yourself with patch-package if you want to use the latest version until the fix is released (that's what I'm doing). Or revert, yeah.

Published as 4.7.2 @qtiki

Published as 4.7.2 @qtiki

Can confirm it's working now. 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

laurentpierson picture laurentpierson  路  3Comments

hnordt picture hnordt  路  3Comments

rodinhart picture rodinhart  路  3Comments

amelon picture amelon  路  3Comments

carlbarrdahl picture carlbarrdahl  路  3Comments