Skip to content

Extraneous names for current state type #241

@Pumpuli

Description

@Pumpuli

A machine's current property type ends up containing extra property names.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions