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

Upgrade TypeScript version used in the repo #3559

Merged
merged 7 commits into from Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .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`.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Expand Up @@ -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"
}
}
9 changes: 5 additions & 4 deletions packages/core/src/StateNode.ts
Expand Up @@ -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]) {
davidkpiano marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/interpreter.ts
Expand Up @@ -1183,7 +1183,7 @@ export class Interpreter<
}
public spawnMachine<
TChildContext,
TChildStateSchema,
TChildStateSchema extends StateSchema,
davidkpiano marked this conversation as resolved.
Show resolved Hide resolved
TChildEvent extends EventObject
>(
machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types.ts
Expand Up @@ -409,7 +409,7 @@ export type StateNodesConfig<
> = {
[K in keyof TStateSchema['states']]: StateNode<
TContext,
TStateSchema['states'][K],
TStateSchema['states'][K] & {},
davidkpiano marked this conversation as resolved.
Show resolved Hide resolved
TEvent
>;
};
Expand All @@ -422,7 +422,7 @@ export type StatesConfig<
> = {
[K in keyof TStateSchema['states']]: StateNodeConfig<
TContext,
TStateSchema['states'][K],
TStateSchema['states'][K] & {},
TEvent,
TAction
>;
Expand All @@ -435,7 +435,7 @@ export type StatesDefinition<
> = {
[K in keyof TStateSchema['states']]: StateNodeDefinition<
TContext,
TStateSchema['states'][K],
TStateSchema['states'][K] & {},
TEvent
>;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/types.test.ts
Expand Up @@ -440,7 +440,7 @@ describe('context', () => {
});

it('should work with generic context', () => {
function createMachineWithExtras<TContext>(
function createMachineWithExtras<TContext extends {}>(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably was a slight bug in the past and it got uncovered by the new, more conservative, rules around unconstrained generics. To fix some inference problems we have introduced LowInfer here:

context?: LowInfer<TContext | (() => TContext)>;

We didn't really want to constrain the TContext to be a subtype of {} but that's the effect with the current version of TS. In practice, this shouldn't be a big problem because we only accept object contexts at runtime. Some people might be forced to add extends {} in their generic declarations, just like I've done here, but that's just about it.

context: TContext
): StateMachine<TContext, any, any> {
return createMachine({ context });
Expand Down
2 changes: 1 addition & 1 deletion packages/xstate-analytics/package.json
Expand Up @@ -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": {}
Expand Down
2 changes: 1 addition & 1 deletion packages/xstate-fsm/package.json
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion packages/xstate-graph/package.json
Expand Up @@ -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": {}
Expand Down
2 changes: 1 addition & 1 deletion packages/xstate-immer/package.json
Expand Up @@ -43,7 +43,7 @@
"devDependencies": {
"immer": "^9.0.6",
"lerna-alias": "3.0.3-0",
"typescript": "^4.5.2",
"typescript": "^4.8.2",
"xstate": "*"
}
}
2 changes: 1 addition & 1 deletion packages/xstate-inspect/package.json
Expand Up @@ -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": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/xstate-react/package.json
Expand Up @@ -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": "*"
}
}
10 changes: 5 additions & 5 deletions packages/xstate-react/src/useInterpret.ts
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/xstate-scxml/package.json
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion packages/xstate-svelte/package.json
Expand Up @@ -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": "*"
}
}
2 changes: 1 addition & 1 deletion packages/xstate-test/package.json
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/xstate-vue/package.json
Expand Up @@ -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": "*"
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -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"
Expand Down