Example from documentation doesn't typecheck
gleachkr opened this issue · comments
The minimal example from the documentation:
import { syncedStore, getYjsValue } from "@syncedstore/core";
import { WebrtcProvider } from "y-webrtc";
// (optional, define types for TypeScript)
type Vehicle = { color: string; brand: string };
// Create your SyncedStore store
export const store = syncedStore({ vehicles: [] as Vehicle[] });
// Get the Yjs document and sync automatically using y-webrtc
const doc = getYjsValue(store);
const webrtcProvider = new WebrtcProvider("my-document-id", doc);
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'.
Thanks. Did a quick fix in ab2155f (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);