-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript Error in Devtools: TransactionEvent
#873
Comments
TransactionEvent
TransactionEvent
TransactionEvent
@devleejb Could I give it a try? i want to challenge it |
@gwbaik9717
Type 'DocEvent<Indexable, OperationInfo>' does not have property 'source' because within the DocEvent type, ConnectionChangeEvent and SyncStatusChangedEvent do not have a source property. It seems like this error occurs. Is it correct to add a source to ConnectionChangeEvent and SyncStatusChangedEvent, or is it correct to use the type guard function in the History.tsx file to check whether it is an event type with a source property and then access it? for example
After writing this
Is it correct to display it like this? |
@chacha912 |
@devleejb I tried to make this work, but I got stuck because it needed too many changes in the devtools types and other areas. Thank you, @KimKyuHoi , for your interest. I think we could fix this by following these steps:
yorkie-js-sdk/src/devtools/index.ts Lines 84 to 98 in 3e6d0b2
We could create a new type for these specific events: /**
* `EventsForDocRebuild` is a list of events used to rebuild a document.
*/
export type EventsForDocRebuild<
P extends Indexable = Indexable,
T = OperationInfo,
> = Array<
| StatusChangedEvent
| SnapshotEvent
| LocalChangeEvent<T, P>
| RemoteChangeEvent<T, P>
| InitializedEvent<P>
| WatchedEvent<P>
| UnwatchedEvent<P>
| PresenceChangedEvent<P>
>;
/**
* `isEventsForDocRebuild` checks if an event can be used to rebuild a document.
*/
export function isEventsForDocRebuild(
event: TransactionEvent,
): event is EventsForDocRebuild {
const typesForDocRebuild = [
DocEventType.StatusChanged,
DocEventType.Snapshot,
DocEventType.LocalChange,
DocEventType.RemoteChange,
DocEventType.Initialized,
DocEventType.Watched,
DocEventType.Unwatched,
DocEventType.PresenceChanged,
];
return event.every((docEvent) =>
typesForDocRebuild.includes(docEvent.type),
);
} This way, we can be more sure that we're using the right events for rebuilding documents, and it's easier for TypeScript to check if we're doing it correctly. |
@chacha912 |
Description:
There is a type-related error in the existing code within the
tools/devtools/src/devtools/tabs/History.tsx
directory related to TransactionEvent. The TypeScript error message is as follows:Why:
This change will help prevent potential bugs, ensure type safety, and improve overall code quality.
The text was updated successfully, but these errors were encountered: