Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Bug report: Inline actions declared on the onDone attribute of invoked services are not fully typed #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Machine, interpret } from '@xstate/compiled';

type Data = {
yeah: boolean;
};

interface Context {
data: Data;
}

type Event =
| { type: 'MAKE_FETCH'; params: { id: string } }
| { type: 'CANCEL' }
| { type: 'done.invoke.makeFetch'; data: Data };

const machine = Machine<Context, Event, 'withStronglyTypedInlineService'>({
initial: 'idle',
states: {
idle: {
on: {
MAKE_FETCH: 'pending',
},
},
pending: {
invoke: [
{
src: 'makeFetch',
onDone: {
target: 'success',
actions: [
(context, event) => {
// @ts-expect-error
typeof event.data.yeah === 'string';
},
],
},
},
],
entry: (ctx, event) => {
console.log(event.params.id);
},
},
success: {},
},
});

interpret(machine, {
services: {
// @ts-expect-error
makeFetch: () => {
return Promise.resolve({
something: 'awesome',
});
},
},
});