diff --git a/crates/loro-wasm/src/lib.rs b/crates/loro-wasm/src/lib.rs index b7023b92e..e06576332 100644 --- a/crates/loro-wasm/src/lib.rs +++ b/crates/loro-wasm/src/lib.rs @@ -1382,7 +1382,7 @@ impl LoroText { /// Whether the container is attached to a docuemnt. /// /// If it's detached, the operations on the container will not be persisted. - #[wasm_bindgen(js_name = "isAttached", skip_typescript)] + #[wasm_bindgen(js_name = "isAttached")] pub fn is_attached(&self) -> bool { self.handler.is_attached() } @@ -1702,7 +1702,7 @@ impl LoroMap { /// Whether the container is attached to a docuemnt. /// /// If it's detached, the operations on the container will not be persisted. - #[wasm_bindgen(js_name = "isAttached", skip_typescript)] + #[wasm_bindgen(js_name = "isAttached")] pub fn is_attached(&self) -> bool { self.handler.is_attached() } @@ -1970,7 +1970,7 @@ impl LoroList { /// Whether the container is attached to a docuemnt. /// /// If it's detached, the operations on the container will not be persisted. - #[wasm_bindgen(js_name = "isAttached", skip_typescript)] + #[wasm_bindgen(js_name = "isAttached")] pub fn is_attached(&self) -> bool { self.handler.is_attached() } @@ -2372,7 +2372,7 @@ impl LoroTree { /// Whether the container is attached to a docuemnt. /// /// If it's detached, the operations on the container will not be persisted. - #[wasm_bindgen(js_name = "isAttached", skip_typescript)] + #[wasm_bindgen(js_name = "isAttached")] pub fn is_attached(&self) -> bool { self.handler.is_attached() } diff --git a/loro-js/src/index.ts b/loro-js/src/index.ts index 291652c57..9dfbd964f 100644 --- a/loro-js/src/index.ts +++ b/loro-js/src/index.ts @@ -199,56 +199,51 @@ declare module "loro-wasm" { interface Loro = Record> { getTypedMap( name: Key, - ): T[Key] extends LoroMap ? SetAttached : never; + ): T[Key] extends LoroMap ? T[Key] : never; getTypedList( name: Key, - ): T[Key] extends LoroList ? SetAttached : never; - getMap(key: string | ContainerID): LoroMap; - getList(key: string | ContainerID): LoroList; - getTree(key: string | ContainerID): LoroTree; - getText(key: string | ContainerID): LoroText; + ): T[Key] extends LoroList ? T[Key] : never; + getMap(key: string | ContainerID): LoroMap; + getList(key: string | ContainerID): LoroList; + getTree(key: string | ContainerID): LoroTree; + getText(key: string | ContainerID): LoroText; } interface LoroList< T extends any[] = any[], - Attached extends boolean = false, > { new (): LoroList; insertContainer( pos: number, child: C, - ): SetAttached; - get(index: number): undefined | Value | SetAttached; + ): C; + get(index: number): undefined | Value | Container; getTyped(loro: Loro, index: Key): T[Key]; insertTyped(pos: Key, value: T[Key]): void; insert(pos: number, value: Value): void; delete(pos: number, len: number): void; subscribe(txn: Loro, listener: Listener): number; getAttached(): undefined | LoroList; - isAttached(): Attached; } interface LoroMap< T extends Record = Record, - Attached extends boolean = false, > { new (): LoroMap; getOrCreateContainer( key: string, child: C, - ): SetAttached; + ): C; setContainer( key: string, child: C, - ): SetAttached; - get(key: string): undefined | Value | SetAttached; + ): C; + get(key: string): undefined | Value | Container; getTyped(txn: Loro, key: Key): T[Key]; set(key: string, value: Value): void; setTyped(key: Key, value: T[Key]): void; delete(key: string): void; subscribe(txn: Loro, listener: Listener): number; - getAttached(): undefined | LoroMap; - isAttached(): Attached; } interface LoroText { @@ -256,41 +251,28 @@ declare module "loro-wasm" { insert(pos: number, text: string): void; delete(pos: number, len: number): void; subscribe(txn: Loro, listener: Listener): number; - getAttached(): undefined | LoroText; - isAttached(): Attached; } interface LoroTree< T extends Record = Record, - Attached extends boolean = false, > { new (): LoroTree; - createNode(parent: TreeID | undefined): LoroTreeNode; + createNode(parent: TreeID | undefined): LoroTreeNode; move(target: TreeID, parent: TreeID | undefined): void; delete(target: TreeID): void; has(target: TreeID): boolean; getNodeByID(target: TreeID): LoroTreeNode; subscribe(txn: Loro, listener: Listener): number; - getAttached(): undefined | LoroTree; - isAttached(): Attached; } interface LoroTreeNode< T extends Record = Record, - Attached extends boolean = false, > { - readonly data: LoroMap; - createNode(): LoroTreeNode; + readonly data: LoroMap; + createNode(): LoroTreeNode; setAsRoot(): void; - moveTo(parent: LoroTreeNode): void; + moveTo(parent: LoroTreeNode): void; parent(): LoroTreeNode | undefined; - children(): Array>; + children(): Array>; } } - -type SetAttached = T extends - LoroMap ? LoroMap - : T extends LoroList ? LoroList - : T extends LoroTree ? LoroTree - : T extends LoroText ? LoroText - : never; diff --git a/loro-js/tests/type.test.ts b/loro-js/tests/type.test.ts index bb724e7af..87dd69cf2 100644 --- a/loro-js/tests/type.test.ts +++ b/loro-js/tests/type.test.ts @@ -5,25 +5,3 @@ test("You shuold not insert a container by using `insert` function", () => { const list = new LoroList(); expectTypeOf(list).not.toMatchTypeOf(); }); - -test("Container attached state", () => { - const list = new LoroList(); - expect(list.isAttached()).toBe(false); - expectTypeOf(list.isAttached()).toMatchTypeOf(); - const doc = new Loro(); - { - const map = doc.getMap("map"); - expectTypeOf(map.isAttached()).toMatchTypeOf(); - expectTypeOf(map).toMatchTypeOf>(); - } - { - const map = new LoroMap(); - expectTypeOf(map.isAttached()).toMatchTypeOf(); - expectTypeOf(map).toMatchTypeOf>(); - } - { - const map = list.insertContainer(0, new LoroMap()); - expectTypeOf(map.isAttached()).toMatchTypeOf(); - expectTypeOf(map).toMatchTypeOf>(); - } -});