import { describe, it } from "@std/testing/bdd"; import { Mutable } from "@commontools/utils/types"; type ImmutableObj = { readonly prop: T; }; function mutate(value: T, callback: (v: Mutable) => void) { callback(value as Mutable); } describe("types", () => { describe("Mutable", () => { it("Enables mutation on nested `{ readonly prop: T }`", () => { const schema: ImmutableObj> = { prop: { prop: 5 } }; mutate(schema, (schema) => { schema.prop.prop = 10; }); }); it("Enables mutation on nested `Readonly`", () => { const schema: Readonly<{ prop: Readonly<{ prop: number; }>; }> = { prop: { prop: 5 } }; mutate(schema, (schema) => { schema.prop.prop = 10; }); }); it("Enables mutation on `ReadonlyArray`", () => { const schema: ReadonlyArray = [1, 2, 3]; mutate(schema, (schema) => { schema[1] = 100; }); }); it("Enables mutation on `readonly T[]`", () => { const schema: readonly number[] = [1, 2, 3]; mutate(schema, (schema) => { schema[1] = 100; }); }); it("Enables mutation on `ReadonlyArray` nested in `Readonly`", () => { const schema: Readonly<{ prop: ReadonlyArray; }> = { prop: [1, 2, 3] }; mutate(schema, (schema) => { schema.prop[1] = 100; }); }); it("Passes through for primitive types", () => { const _: Mutable = null; const __: Mutable = 5; const ___: Mutable = "hi"; }); }); });