-
-
Notifications
You must be signed in to change notification settings - Fork 117
Open
Description
Problem
The entries() method on LoroMap currently has a fixed return type:
entries(): ([string, Value | Container])[];This makes it difficult to use with branded/nominal string types for keys. Many TypeScript codebases use branded types for IDs to provide additional type-level safety:
type SeminarId = string & { readonly _brand: unique symbol };
type RoomId = string & { readonly _brand: unique symbol };
// When iterating over a map with SeminarId keys, we lose the brand information
const map: LoroMap<SeminarId, SomeValue> = ...;
const entries = map.entries(); // Returns [string, Value | Container][] - SeminarId brand is lostProposed Solution
Make the entries() method generic to preserve the key type:
entries(): ([K, Value | Container])[];
// or if LoroMap already has a key type parameter:
entries(): ([KeyType, Value | Container])[];This would allow branded string types to flow through correctly:
const entries = map.entries(); // Returns [SeminarId, Value | Container][]Use Case
We're building a planning system where we have multiple entity types (seminars, rooms, bookings, etc.) each with their own branded ID type. When iterating over CRDT maps, we currently lose this type information and have to cast manually, which defeats the purpose of having branded types for type safety.
Environment
- loro-crdt version: 1.8.8
- TypeScript 5.9
Thank you for considering this enhancement!
Metadata
Metadata
Assignees
Labels
No labels