Type definitions for structured documents

I started drafting type definitions that could be used to describe structured documents, which is how I’ve so far used Y.js in all of my use cases. The key change to current Y.js types is that Y.Map would be defined in terms of a structure instead of a string-to-value map. So for instance, your structure could be

interface Item {
  id: number;
  title: string;
  description?: string | undefined
  tasks: Y.Array<string>
}

You could then use a Y.Map<Item> to provide a typesafe interface to this data. This interface would not allow you to access non-existing fields, or for instance, or delete non-optional fields.

For simple key-value maps, you could now use the type Y.Map<Record<string, Item>>. I see that this would be a breaking change to TypeScript users which is why I’d like to gauge how that would be received.

My initial draft (a separate TypeScript codebase that just introduces new types on top of existing Y.js implementation) is here y-typed/src/hello.ts at master · raimohanska/y-typed · GitHub. I might next see if I can come up with a Pull Request that introduces new typings for at least Y.Map and possibly Y.Doc. But only if you think this is worthwhile and could be on the roadmap for Y.js

What do you think folks?