Make LoroMap.entries() generic to support branded string types

オープン
#889 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
api

調査の方向性

まず、LoroMap.entries() の TypeScript 定義と実装を見つけ、LoroMap がキーの型をどのように宣言しているかを確認します。ブランド付き文字列キーを使った型レベルのチェックを追加し、entries() がキャストなしでキーの型を保持することを検証します。ブランド付きキーの例が型チェックを通過し、既存の entries() の動作との互換性が維持されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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 lost

Proposed 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!

主要言語
Rust
スター
6.3k
フォーク
205
平均マージ
3日 18時間
マージ済み PR(30日)
45

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

loro-dev/loro のほかの issue

loro-dev/loro の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。