From d7704516e0660ee902326573cc35049ee80d623c Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Tue, 3 Nov 2026 08:32:03 +0000 Subject: [PATCH] fix(chord): int() table keys type as numbers again (a TypeBox leftover) --- packages/chord/src/store/table.ts | 6 +----- packages/chord/test/store/table.test.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/chord/src/store/table.ts b/packages/chord/src/store/table.ts index d86d2fa16..08f53d322 100644 --- a/packages/chord/src/store/table.ts +++ b/packages/chord/src/store/table.ts @@ -29,11 +29,7 @@ export type TableOptions[], /** The key of a row of a table with columns `C` and key `K`: an object with exactly the key columns. */ export type KeyOf = { - 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; }; /** diff --git a/packages/chord/test/store/table.test.ts b/packages/chord/test/store/table.test.ts index ad7c524e2..dc52cd7e9 100644 --- a/packages/chord/test/store/table.test.ts +++ b/packages/chord/test/store/table.test.ts @@ -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 = { id: 7 }; + const mixed: KeyOf = { id: "a", at: 1 }; + expect([key, mixed]).toEqual([{ id: 7 }, { id: "a", at: 1 }]); + }); +});