Closed gleachkr closed 1 year ago
Thanks. Did a quick fix in https://github.com/YousefED/SyncedStore/commit/ab2155f2322d9a7a8045ccba25ec6de3b65b576d (you can simply cast with as any
), but will add a getYjsDoc
value later that works only on Docs and returns the correct type :)
Awesome. Thanks for this project!
For that problem I have created the Y.Doc
before, like this:
import * as Y from "yjs";
import { syncedStore, getYjsValue } from "@syncedstore/core";
import { WebrtcProvider } from "y-webrtc";
// (optional, define types for TypeScript)
type Vehicle = { color: string; brand: string };
const ydoc = new Y.Doc();
// Create your SyncedStore store
export const store = syncedStore({ vehicles: [] as Vehicle[] }, ydoc);
// Get the Yjs document and sync automatically using y-webrtc
const webrtcProvider = new WebrtcProvider("my-document-id", ydoc);
The minimal example from the documentation:
Doesn't typecheck on line 12, because
Argument of type 'Doc | AbstractType<any> | undefined' is not assignable to parameter of type 'Doc'. Type 'undefined' is not assignable to type 'Doc'.