import { describe, it } from "@std/testing/bdd"; import type { Cell, ComparableCell, HandlerState, OpaqueCell, ReadonlyCell, Stream, WriteonlyCell, } from "@commonfabric/api"; import type { MustBeTrue, Same } from "@commonfabric/utils/types"; interface Item { id: string; } declare function appendItem(list: WriteonlyCell, item: Item): void; describe("HandlerState", () => { // The assertions are the type checker's, and `deno task check` is what runs // them. `Same` yields `false` on a mismatch, which `MustBeTrue` refuses. it("passes a cell of every kind through unchanged", () => { type _Cell = MustBeTrue>, Cell>>; type _Readonly = MustBeTrue< Same>, ReadonlyCell> >; type _Writeonly = MustBeTrue< Same>, WriteonlyCell> >; type _Comparable = MustBeTrue< Same>, ComparableCell> >; type _Opaque = MustBeTrue< Same>, OpaqueCell> >; type _Stream = MustBeTrue>, Stream>>; }); it("passes a cell held in a state field through unchanged", () => { type _Field = MustBeTrue< Same< HandlerState<{ list: WriteonlyCell; pick: ReadonlyCell }>, { readonly list: WriteonlyCell; readonly pick: ReadonlyCell; } > >; // Never called: the call to `appendItem` compiles only when the field is // still a `WriteonlyCell`. const _probe = (state: HandlerState<{ list: WriteonlyCell }>) => appendItem(state.list, { id: "a" }); }); it("makes plain data readonly at every depth", () => { type _Data = MustBeTrue< Same< HandlerState<{ count: number; items: Item[] }>, { readonly count: number; readonly items: ReadonlyArray<{ readonly id: string }>; } > >; }); });