Extraneous names for current state type
A machine's `current` property type ends up containing extra property names.
```ts
const machine = createMachine({
a: state(),
b: state()
});
type Foo = typeof machine['current'];
// Expected:
// type Foo = 'a' | 'b';
// Actual:
// type Foo = 'a' | 'b' | keyof MachineState<string>;
// (Expands to):
// type Foo = 'a' | 'b' | 'final' | 'transitions' | 'immediate' | 'enter';
```
I believe this is caused by the change to `createMachine()` type in 4f6fb69. Even though the third type argument to `Machine` in the return value is unchanged: `AllStateKeys<S>`, the type of `S` was changed. Now `S` is a full `MachineStates` object, whose values are objects with keys `final`, `transitions`, `immediate` and `enter`. So when passing a full `MachineState` to `AllStateKeys`, it extracts nested keys too. Thus the result is all the state keys plus the nested `final`, `transitions`, `immediate` and `enter`.
1 条评论