diff --git a/.changeset/cuddly-crabs-fix.md b/.changeset/cuddly-crabs-fix.md new file mode 100644 index 0000000000..d2b4ff3655 --- /dev/null +++ b/.changeset/cuddly-crabs-fix.md @@ -0,0 +1,5 @@ +--- +'xstate': patch +--- + +Fixed minor compatibility issues with TypeScript 4.8 in the codebase. This fixes the typechecking with TypeScript 4.8 in projects that don't use `skipLibCheck: true`. diff --git a/package.json b/package.json index 0a5cbf7a10..f393b5c139 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "ts-jest": "^26.5.6", "tslib": "^2.3.1", "tslint": "^5.11.0", - "typescript": "^4.5.2", + "typescript": "^4.8.2", "webpack-dev-middleware": "^3.6.0" }, "resolutions": { diff --git a/packages/core/package.json b/packages/core/package.json index 7dddc7159e..7c4f1c17b1 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -63,7 +63,7 @@ "rxjs": "^7.1.0", "ts-jest": "^26.5.6", "tslib": "^2.3.1", - "typescript": "^4.5.2", + "typescript": "^4.8.2", "xml-js": "^1.6.11" } } diff --git a/packages/core/src/StateNode.ts b/packages/core/src/StateNode.ts index 33b80d7b31..b2be12d749 100644 --- a/packages/core/src/StateNode.ts +++ b/packages/core/src/StateNode.ts @@ -1629,16 +1629,17 @@ class StateNode< (stateNode) => !(stateNode.type === 'history') ); } else if (this.initial !== undefined) { - if (!this.states[this.initial]) { + if (!this.states[this.initial as string]) { throw new Error( - `Initial state '${this.initial}' not found on '${this.key}'` + `Initial state '${this.initial as string}' not found on '${this.key}'` ); } - initialStateValue = (isLeafNode(this.states[this.initial]) + initialStateValue = (isLeafNode(this.states[this.initial as string]) ? this.initial : { - [this.initial]: this.states[this.initial].initialStateValue + [this.initial]: this.states[this.initial as string] + .initialStateValue }) as StateValue; } else { // The finite state value of a machine without child states is just an empty object diff --git a/packages/core/src/interpreter.ts b/packages/core/src/interpreter.ts index 1f8a0beaa8..b7f4b56c3a 100644 --- a/packages/core/src/interpreter.ts +++ b/packages/core/src/interpreter.ts @@ -1183,7 +1183,7 @@ export class Interpreter< } public spawnMachine< TChildContext, - TChildStateSchema, + TChildStateSchema extends StateSchema, TChildEvent extends EventObject >( machine: StateMachine, diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index f44df827fb..8ced58855c 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -409,7 +409,7 @@ export type StateNodesConfig< > = { [K in keyof TStateSchema['states']]: StateNode< TContext, - TStateSchema['states'][K], + TStateSchema['states'][K] & {}, TEvent >; }; @@ -422,7 +422,7 @@ export type StatesConfig< > = { [K in keyof TStateSchema['states']]: StateNodeConfig< TContext, - TStateSchema['states'][K], + TStateSchema['states'][K] & {}, TEvent, TAction >; @@ -435,7 +435,7 @@ export type StatesDefinition< > = { [K in keyof TStateSchema['states']]: StateNodeDefinition< TContext, - TStateSchema['states'][K], + TStateSchema['states'][K] & {}, TEvent >; }; diff --git a/packages/core/test/types.test.ts b/packages/core/test/types.test.ts index 6599a3daa0..4708242bb8 100644 --- a/packages/core/test/types.test.ts +++ b/packages/core/test/types.test.ts @@ -440,7 +440,7 @@ describe('context', () => { }); it('should work with generic context', () => { - function createMachineWithExtras( + function createMachineWithExtras( context: TContext ): StateMachine { return createMachine({ context }); diff --git a/packages/xstate-analytics/package.json b/packages/xstate-analytics/package.json index 5bf57884e3..6910a8c4d4 100644 --- a/packages/xstate-analytics/package.json +++ b/packages/xstate-analytics/package.json @@ -41,7 +41,7 @@ "jest": "^26.6.3", "lerna-alias": "3.0.3-0", "ts-jest": "^26.5.6", - "typescript": "^4.5.2", + "typescript": "^4.8.2", "xstate": "*" }, "dependencies": {} diff --git a/packages/xstate-fsm/package.json b/packages/xstate-fsm/package.json index 8ccc6e2537..fe7d2368f3 100644 --- a/packages/xstate-fsm/package.json +++ b/packages/xstate-fsm/package.json @@ -50,6 +50,6 @@ "rollup-plugin-terser": "^5.1.2", "rollup-plugin-typescript2": "^0.30.0", "ts-jest": "^26.5.6", - "typescript": "^4.5.2" + "typescript": "^4.8.2" } } diff --git a/packages/xstate-graph/package.json b/packages/xstate-graph/package.json index ec0a6740d4..8618e0cfa2 100644 --- a/packages/xstate-graph/package.json +++ b/packages/xstate-graph/package.json @@ -43,7 +43,7 @@ "jest": "^26.6.3", "lerna-alias": "3.0.3-0", "ts-jest": "^26.5.6", - "typescript": "^4.5.2", + "typescript": "^4.8.2", "xstate": "*" }, "dependencies": {} diff --git a/packages/xstate-immer/package.json b/packages/xstate-immer/package.json index 2d950952a2..e4dbc4bd3a 100644 --- a/packages/xstate-immer/package.json +++ b/packages/xstate-immer/package.json @@ -43,7 +43,7 @@ "devDependencies": { "immer": "^9.0.6", "lerna-alias": "3.0.3-0", - "typescript": "^4.5.2", + "typescript": "^4.8.2", "xstate": "*" } } diff --git a/packages/xstate-inspect/package.json b/packages/xstate-inspect/package.json index 32e3902481..e922ec209d 100644 --- a/packages/xstate-inspect/package.json +++ b/packages/xstate-inspect/package.json @@ -46,7 +46,7 @@ "rollup-plugin-replace": "^2.2.0", "rollup-plugin-terser": "^5.1.2", "rollup-plugin-typescript2": "^0.30.0", - "typescript": "^4.5.2", + "typescript": "^4.8.2", "ws": "^8.4.0", "xstate": "*" }, diff --git a/packages/xstate-react/package.json b/packages/xstate-react/package.json index 18bf9df397..af8105329f 100644 --- a/packages/xstate-react/package.json +++ b/packages/xstate-react/package.json @@ -88,7 +88,7 @@ "rollup-plugin-terser": "^5.1.2", "rollup-plugin-typescript2": "^0.30.0", "ts-jest": "^26.5.6", - "typescript": "^4.5.2", + "typescript": "^4.8.2", "xstate": "*" } } diff --git a/packages/xstate-react/src/useInterpret.ts b/packages/xstate-react/src/useInterpret.ts index 80dc8c0e28..96be7a0250 100644 --- a/packages/xstate-react/src/useInterpret.ts +++ b/packages/xstate-react/src/useInterpret.ts @@ -75,11 +75,11 @@ export function useIdleInterpreter( // This mutation assignment is safe because the service instance is only used // in one place -- this hook's caller. useIsomorphicLayoutEffect(() => { - Object.assign(service.machine.options.actions, actions); - Object.assign(service.machine.options.guards, guards); - Object.assign(service.machine.options.activities, activities); - Object.assign(service.machine.options.services, services); - Object.assign(service.machine.options.delays, delays); + Object.assign(service.machine.options.actions!, actions); + Object.assign(service.machine.options.guards!, guards); + Object.assign(service.machine.options.activities!, activities); + Object.assign(service.machine.options.services!, services); + Object.assign(service.machine.options.delays!, delays); }, [actions, guards, activities, services, delays]); return service as any; diff --git a/packages/xstate-scxml/package.json b/packages/xstate-scxml/package.json index 3f28aaab1c..db76f63ca6 100644 --- a/packages/xstate-scxml/package.json +++ b/packages/xstate-scxml/package.json @@ -42,6 +42,6 @@ "jest": "^26.6.3", "lerna-alias": "3.0.3-0", "ts-jest": "^26.5.6", - "typescript": "^4.5.2" + "typescript": "^4.8.2" } } diff --git a/packages/xstate-svelte/package.json b/packages/xstate-svelte/package.json index fef3938aa1..7be79ba94e 100644 --- a/packages/xstate-svelte/package.json +++ b/packages/xstate-svelte/package.json @@ -69,7 +69,7 @@ "svelte-jester": "^1.1.2", "svelte-preprocess": "^4.0.10", "ts-jest": "^26.5.6", - "typescript": "^4.5.2", + "typescript": "^4.8.2", "xstate": "*" } } diff --git a/packages/xstate-test/package.json b/packages/xstate-test/package.json index 1ef344de4e..e5c9649fcf 100644 --- a/packages/xstate-test/package.json +++ b/packages/xstate-test/package.json @@ -47,7 +47,7 @@ "lerna-alias": "3.0.3-0", "strip-ansi": "^5.2.0", "ts-jest": "^26.5.6", - "typescript": "^4.5.2", + "typescript": "^4.8.2", "xstate": "*" }, "dependencies": { diff --git a/packages/xstate-vue/package.json b/packages/xstate-vue/package.json index 9af97cbe9f..be1457e148 100644 --- a/packages/xstate-vue/package.json +++ b/packages/xstate-vue/package.json @@ -68,7 +68,7 @@ "rollup-plugin-terser": "^5.1.2", "rollup-plugin-typescript2": "^0.30.0", "ts-jest": "^26.5.6", - "typescript": "^4.5.2", + "typescript": "^4.8.2", "vue": "^3.0.7", "vue-jest": "5.0.0-alpha.7", "xstate": "*" diff --git a/yarn.lock b/yarn.lock index 74d658abfd..326267c5da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8100,10 +8100,10 @@ typescript@*: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3" integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA== -typescript@^4.5.2: - version "4.5.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.2.tgz#8ac1fba9f52256fdb06fb89e4122fa6a346c2998" - integrity sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw== +typescript@^4.8.2: + version "4.8.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.2.tgz#e3b33d5ccfb5914e4eeab6699cf208adee3fd790" + integrity sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw== uglify-js@^3.4.9: version "3.12.3"