Description
Bug Report
π Search Terms
sensitive, order, ordering, loading
π Version & Regression Information
This doesn't work correctly with 4.3 and 4.4
β― Repository Link
https://github.com/statelyai/xstate-viz/tree/58b255c0769f2e9e0c292864057d83f50fe1b31b/src
(it's not possible to create a playground for this since the repro involves multiple files)
π» Code
This is not yet a minimal repro case but I have spent a lot of time on creating a minimal consuming/application code that triggers the problem. If the TS team confirms that this is an issue I might try to reduce this further down but maybe this is a duplicate of some issue that I couldn't find so it might turn out that spending more hours on this wouldn't be worth it.
// App.tsx
import { StateNode } from 'xstate';
export function toDirectedGraph(stateNode: StateNode): void {
[stateNode].map((target) => {});
}
// EmbedPreview.tsx
import { useMachine } from '@xstate/react';
import { createModel } from 'xstate/lib/model';
import { send } from 'xstate';
const embedPreviewModel = createModel(
{
embedUrl: '',
},
{
events: {
PARAMS_CHANGED: (params: { foo: string }) => ({ params }),
PREVIEW: () => ({}),
IFRAME_LOADED: () => ({}),
IFRAME_ERROR: () => ({}),
},
},
);
const embedPreviewMachine = embedPreviewModel.createMachine({
entry: send('ada'),
});
useMachine(embedPreviewMachine, {
actions: {
saveParams: embedPreviewModel.assign({
embedUrl: (_, e) => (e as any).params,
}),
},
});
π Actual behavior
When running yarn tsc
I get an error at src/EmbedPreview.tsx:23:12
, but if I make any of those changes the error "goes away":
- remove
App.tsx
- rename
App.tsx
to something coming afterEmbedPreview.tsx
(alphabetically) - remove the unused
target
parameter in the callback withintoDirectedGraph
in theApp.tsx
π Expected behavior
Error reports should be consistent and not prone to the order in which files are loaded and in which some types are utilized (I suspect the latter is somehow related to some type info being lazily loaded/evaluated and that's why removing the callback parameter "helps").
More details
We've noticed a weird thing on this branch:
https://github.com/statelyai/xstate-viz/tree/ef97512b8d11b6bba752a287bf2efc6453a9a02e
The tsc
has started to report a problem within this call:
https://github.com/statelyai/xstate-viz/blob/ef97512b8d11b6bba752a287bf2efc6453a9a02e/src/EmbedPreview.tsx#L147
However, the error could not be observed in the VScode.
I've made sure that VScode and tsc
are running using the same TS version but yet still the VScode didn't report this issue. I've observed some more weird behaviors - after changing some lines of code I've seen some inferred values (related to this useMachine
call) to change despite no code changes (start with code A, make changes, roll back -> different inference results at the beginning and at the end of the process).
So I've started to remove stuff from our project to get this somewhat minimal repro case. Somewhere during the process, VScode has started to show the error but I've noticed that now I seemingly irrelevant changes changed the output of the tsc
and I've focused on that.