Skip to content

Commit

Permalink
Fixed compatibility of Interpreter with older versions of TypeScript (
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist authored Mar 11, 2022
1 parent e08030f commit 4cf89b5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-snakes-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': patch
---

Fixed compatibility of `Interpreter` with older versions of TypeScript. This ensures that our interpreters can correctly be consumed by functions expecting `ActorRef` interface (like for example `useSelector`).
29 changes: 28 additions & 1 deletion packages/core/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { terser } from 'rollup-plugin-terser';
import rollupReplace from 'rollup-plugin-replace';
import fileSize from 'rollup-plugin-filesize';
import glob from 'fast-glob';
import path from 'path';
import fs from 'fs';

const createTsPlugin = ({ declaration = true, target } = {}) =>
typescript({
Expand All @@ -30,7 +32,32 @@ const createNpmConfig = ({ input, output }) => ({
input,
output,
preserveModules: true,
plugins: [createTsPlugin(), createBabelPlugin()]
plugins: [
createTsPlugin(),
createBabelPlugin(),
/** @ts-ignore [symbolObservable] creates problems who are on older versions of TS, remove this plugin when we drop support for TS@<4.3 */
{
writeBundle(outputOptions, bundle) {
const [, dtsAsset] = Object.entries(bundle).find(
([fileName]) => fileName === 'interpreter.d.ts'
);

const dtsPath = path.join(
__dirname,
outputOptions.dir,
'interpreter.d.ts'
);

fs.writeFileSync(
dtsPath,
dtsAsset.source.replace(
'[symbolObservable]():',
'[Symbol.observable]():'
)
);
}
}
]
});

const createUmdConfig = ({ input, output, target = undefined }) => ({
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export enum InterpreterStatus {
Stopped
}

/** @ts-ignore [symbolObservable] creates problems for people without `skipLibCheck` who are on older versions of TS, remove this comment when we drop support for TS@<4.3 */
export class Interpreter<
// tslint:disable-next-line:max-classes-per-file
TContext,
Expand Down Expand Up @@ -1372,7 +1371,6 @@ export class Interpreter<
};
}

/** @ts-ignore this creates problems for people without `skipLibCheck` who are on older versions of TS, remove this comment when we drop support for TS@<4.3 */
public [symbolObservable](): InteropSubscribable<
State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>
> {
Expand Down

0 comments on commit 4cf89b5

Please sign in to comment.