fix(chord): int() table keys type as numbers again (a TypeBox leftover)

This commit is contained in:
Mario Zechner 2026-11-03 08:32:03 +00:00
parent 42849bb840
commit d7704516e0
2 changed files with 11 additions and 6 deletions

View file

@ -29,11 +29,7 @@ export type TableOptions<C extends Columns, K extends readonly OrderColumn<C>[],
/** The key of a row of a table with columns `C` and key `K`: an object with exactly the key columns. */
export type KeyOf<C extends Columns, K extends readonly string[]> = {
readonly [P in K[number]]: P extends keyof C
? C[P] extends { readonly "~kind": "Integer" }
? number
: string
: never;
readonly [P in K[number]]: P extends keyof C ? (C[P] extends { readonly type: "integer" } ? number : string) : never;
};
/**

View file

@ -3,7 +3,7 @@
import { describe, expect, it } from "vitest";
import { int, obj, opt, str } from "../../src/contracts/index.ts";
import { json } from "../../src/store/json-column.ts";
import { defineTable } from "../../src/store/table.ts";
import { defineTable, type KeyOf } from "../../src/store/table.ts";
const columns = { id: str(), path: str(), at: int(), note: opt(str()), meta: json(obj({}), { version: 1 }) };
@ -64,3 +64,12 @@ describe("defineTable", () => {
).not.toBe(a.fingerprint);
});
});
describe("keys", () => {
it("type an int() key column as a number and a str() one as a string (tutorial, 2026-11-03)", () => {
const byNumber = { id: int(), text: str() };
const key: KeyOf<typeof byNumber, ["id"]> = { id: 7 };
const mixed: KeyOf<typeof columns, ["id", "at"]> = { id: "a", at: 1 };
expect([key, mixed]).toEqual([{ id: 7 }, { id: "a", at: 1 }]);
});
});