This PR aims to improve type definitions regarding nested states, and also adds a missing "child" field.
However, this is a naive improvement, far from perfect 😅 , see example below 👇
// now
import { interpret } from 'robot3'
import { wizardMachine } from './wizardMachine'
const service = interpret(wizardMachine)
// ⬆️ TS will infer that service.machine.current can be ➡️ 'end' | 'step1' | 'step2'
const child = service.child // Property 'child' does not exist...
// after PR
import { interpret } from 'robot3'
import { wizardMachine } from './wizardMachine'
const service = interpret(wizardMachine)
// ⬆️ TS will infer that service.machine.current can be ➡️ 'end' | 'step1' | 'step2' | 'idle' | 'validate' | 'finished'
const child = service.child
// ⬆️ TS will infer that child?.machine.current can be ➡️ 'end' | 'step1' | 'step2' | 'idle' | 'validate' | 'finished'
// But it won't be able to infer that service.machine.current can only be ➡️ 'end' | 'step1' | 'step2'
// and that child?.machine.current can only be ➡️ 'idle' | 'validate' | 'finished'
This PR aims to improve type definitions regarding nested states, and also adds a missing "child" field. However, this is a naive improvement, far from perfect 😅 , see example below 👇
Considering this wizard machine:
Nested states: