Open parker-codes opened 2 years ago
This is expected - typegen generates some extra data to aid inference. Inference only works when the contextual type can flow into an expression. In your case, incrementCount
is already predefined elsewhere and thus its type is already "set in stone".
@Andarist is there no way to facilitate sharing code between machines then and still have them typed? Perhaps using a different strategy to remove the "set in stone" functionality?
This does the trick:
@Andarist following your example I have a TS error in actions.ts
:
Property 'incrementCount' does not exist on type 'MachineOptionsActions<ToggleContext, ResolveTypegenMeta<Typegen0, { type: "TOGGLE"; } | { type: "RESET"; }, BaseActionObject, ServiceMap>, { ...; }, MergeWithInternalEvents<...>, IndexByType<...>> | undefined'.ts(2339)
Please always try to share a repro case in a runnable form - either by providing a git repository to clone or a codesandbox. I can’t debug a lot from an error message 😉
Actually, finally, I get this working. I think that just it was hard to reproduce the code from the git diff. Anyway, thanks!
Description
If I use typegen with all options inside of the same file, the types work as expected. If I move any of these options to an external file, typegen cannot infer the method signatures on either end.
Expected result
The tyepgen service could follow the import to correctly infer the type signature of the imported action. Then within the action, I could add type hints to correctly see what the parameters are.
Actual result
A rather long error block is shown underneath the action declaration.
Reproduction
https://github.com/parker-codes/xstate-typegen-import-error
Additional context
There is an
xstate:typegen
command defined in package.json to generate the types.Remove either of the two lines that say
// @ts-expect-error XState Typegen
to view the errors.