std helpers: typed tables, omit, panic, describeError, variants, test helpers, Vue JSX runtime #69

Merged
sionzee merged 2 commits from evobug/fb3-std-helpers into main 2026-11-17 00:09:38 +01:00
Owner

Round 3 of the 0.2.0 adoption feedback, std area, part 2 of 2: std helpers (feedback items 6–14 of this area, from "Std library" and "Performance"). Part 1, validators and types (items 1–5), is #64. Both are from main. They touch json.rs and CHANGELOG.md in different places, so the second to merge should only need a small rebase, if any.

Per feedback item

6. Typed table helpers: done.

  • recordOf(keys, f) (dict): Record<K, V> without Object.fromEntries(...) as. Keys are defined as data, so __proto__ is a key.
  • keysOf(table) (dict): the typed keys of an as const / frozen table. Documented as only for tables you declare, since an interface-typed object can have more keys at runtime.
  • indexIn(tuple, x) (array): Option<0 | 1 | 2>, through the new IndexOf<T>.

7. omit(value, ...keys): done. A copy typed Omit<T, K>. It copies own enumerable keys, symbols included, as a spread does, and never deletes. The absence guide has a new "Dropping an optional key" section.

8. panic(message): never: done.

  • In std's result module and the prelude. It throws an Error named Panic.
  • The checker treats it as never-returning, like process.exit: the branch ends and nothing propagates. The asserts fixture covers a catch branch and a module-level call; no uncaught-propagation.
  • The escape-hatches line now reads N unsafe() block(s), N panic() call(s), N @cache mark(s), ….

9. A common message on std errors: done.

  • NumberError gets message (not a number: "12px").
  • describeError(error) (result) gives one line for a JsonError (path: message), anything with a message, an Err or Panic (what it holds), an Error, or a string.

10. filter(Boolean) narrows: done. A prelude overload on Array / ReadonlyArray returns Truthy<T>[], so (string | false)[] becomes string[]. A new packages/prelude/test type test is part of npm run typecheck.

11. variants<T>(): done. The enum's tags in declaration order, as a frozen array. The build evaluates the type with the validator machinery and replaces the call with Object.freeze([...] as const) satisfies readonly T["tag"][], so tsc checks the list on emit and no helper import is needed. It works through the prelude too. A non-enum type is a json-type error with the reason.

12. Test-only helpers: done.

  • @evobug_com/safe-ts-std/testing:
    • fixture<T>(fields): a deep partial, kept as a plain object;
    • testDouble<T>(fields): a Proxy that throws testDouble: "connect" isn't set on a field it wasn't given, but answers the keys runners and await probe for (then, toJSON, …);
    • unchecked<T>(value);
    • expectPresent(value, what?).
  • New rule test-only-helper (an error in the preset) reports importing them in a file that isn't a test file. A test file is named *.test.* / *.spec.*, sits in a test, tests, __tests__ or __mocks__ directory, or imports node:test / vitest.

13. safe-ts-vue typed JSX runtime: done.

  • @evobug_com/safe-ts-vue/jsx-runtime (and /jsx-dev-runtime) for "jsxImportSource": "@evobug_com/safe-ts-vue": jsx, jsxs, jsxDEV, Fragment, and Vue's JSX types.
  • Like the RTSS client's hand-written runtime, a component's children become its default slot function, so Vue doesn't warn on every render. Elements, fragments and Teleport keep their children; slot objects pass through. It's built on createVNode plus what h adds, with no cast at the call site.

14. Docs lines: done.

  • Vue state guide: an absent Boolean prop is prop<Option<boolean>>(Boolean, { default: undefined }).
  • Testing guide: keep a failing seed as a pinned regression run.
  • Performance guide: q's instanceof on class instances, using the adopter's numbers from the feedback (55 ns inline try, 61–65 ns returning the bytes, 80 ns returning the Writer). My own micro-benchmark was too noisy to publish, so the text names its source.

Docs changed

  • docs/guide/std-helpers.md: module table, plus sections for describeError, tables keyed by a literal union, omit, filter(Boolean), panic.
  • docs/guide/absence.md, docs/guide/enums.md ("Listing the variants"), docs/guide/testing.md (pinned seed; "Partial and fake values"), docs/guide/performance-myths.md, docs/vue/state.md (Boolean prop, JSX runtime), docs/guide/adoption.md (escape-hatches line).
  • New docs/rules/test-only-helper.md, plus docs/README.md rule table, sidebar, README.md (rule table, std and safe-ts-vue tables), CHANGELOG.md (Added, Changed).

Verification

  • npm run build: ok.
  • cargo nextest run --workspace: all passed. New tests: variants transform and errors, the panic fixture, the escape-hatches line.
  • cargo clippy -q --workspace --all-targets: nothing new in the changed code.
  • npm run test:std: 297 passed. New: tables.test.ts, testing.test.ts, safe-ts-vue/test/jsx-runtime.test.ts.
  • npm run typecheck (now with packages/prelude/test) and npm run typecheck:emit: ok.
  • node scripts/docs-typecheck.mjs, npm run test:docs, npm run test:vite, npm run bench:check, node scripts/verify-packages.mjs: all ok.

🤖 Generated with Claude Code

Round 3 of the 0.2.0 adoption feedback, std area, part 2 of 2: **std helpers** (feedback items 6–14 of this area, from "Std library" and "Performance"). Part 1, validators and types (items 1–5), is #64. Both are from `main`. They touch `json.rs` and `CHANGELOG.md` in different places, so the second to merge should only need a small rebase, if any. ## Per feedback item **6. Typed table helpers: done.** - `recordOf(keys, f)` (dict): `Record<K, V>` without `Object.fromEntries(...) as`. Keys are defined as data, so `__proto__` is a key. - `keysOf(table)` (dict): the typed keys of an `as const` / frozen table. Documented as only for tables you declare, since an interface-typed object can have more keys at runtime. - `indexIn(tuple, x)` (array): `Option<0 | 1 | 2>`, through the new `IndexOf<T>`. **7. `omit(value, ...keys)`: done.** A copy typed `Omit<T, K>`. It copies own enumerable keys, symbols included, as a spread does, and never `delete`s. The absence guide has a new "Dropping an optional key" section. **8. `panic(message): never`: done.** - In std's result module and the prelude. It throws an `Error` named `Panic`. - The checker treats it as never-returning, like `process.exit`: the branch ends and nothing propagates. The `asserts` fixture covers a catch branch and a module-level call; no `uncaught-propagation`. - The escape-hatches line now reads `N unsafe() block(s), N panic() call(s), N @cache mark(s), …`. **9. A common `message` on std errors: done.** - `NumberError` gets `message` (`not a number: "12px"`). - `describeError(error)` (result) gives one line for a `JsonError` (`path: message`), anything with a `message`, an `Err` or `Panic` (what it holds), an `Error`, or a string. **10. `filter(Boolean)` narrows: done.** A prelude overload on `Array` / `ReadonlyArray` returns `Truthy<T>[]`, so `(string | false)[]` becomes `string[]`. A new `packages/prelude/test` type test is part of `npm run typecheck`. **11. `variants<T>()`: done.** The enum's tags in declaration order, as a frozen array. The build evaluates the type with the validator machinery and replaces the call with `Object.freeze([...] as const) satisfies readonly T["tag"][]`, so tsc checks the list on emit and no helper import is needed. It works through the prelude too. A non-enum type is a `json-type` error with the reason. **12. Test-only helpers: done.** - `@evobug_com/safe-ts-std/testing`: - `fixture<T>(fields)`: a deep partial, kept as a plain object; - `testDouble<T>(fields)`: a Proxy that throws `testDouble: "connect" isn't set` on a field it wasn't given, but answers the keys runners and `await` probe for (`then`, `toJSON`, …); - `unchecked<T>(value)`; - `expectPresent(value, what?)`. - New rule **`test-only-helper`** (an error in the preset) reports importing them in a file that isn't a test file. A test file is named `*.test.*` / `*.spec.*`, sits in a `test`, `tests`, `__tests__` or `__mocks__` directory, or imports `node:test` / `vitest`. **13. safe-ts-vue typed JSX runtime: done.** - `@evobug_com/safe-ts-vue/jsx-runtime` (and `/jsx-dev-runtime`) for `"jsxImportSource": "@evobug_com/safe-ts-vue"`: `jsx`, `jsxs`, `jsxDEV`, `Fragment`, and Vue's `JSX` types. - Like the RTSS client's hand-written runtime, a component's children become its default slot function, so Vue doesn't warn on every render. Elements, fragments and `Teleport` keep their children; slot objects pass through. It's built on `createVNode` plus what `h` adds, with no cast at the call site. **14. Docs lines: done.** - Vue state guide: an absent Boolean prop is `prop<Option<boolean>>(Boolean, { default: undefined })`. - Testing guide: keep a failing seed as a pinned regression run. - Performance guide: `q`'s `instanceof` on class instances, using the adopter's numbers from the feedback (55 ns inline `try`, 61–65 ns returning the bytes, 80 ns returning the `Writer`). My own micro-benchmark was too noisy to publish, so the text names its source. ## Docs changed - `docs/guide/std-helpers.md`: module table, plus sections for describeError, tables keyed by a literal union, `omit`, `filter(Boolean)`, `panic`. - `docs/guide/absence.md`, `docs/guide/enums.md` ("Listing the variants"), `docs/guide/testing.md` (pinned seed; "Partial and fake values"), `docs/guide/performance-myths.md`, `docs/vue/state.md` (Boolean prop, JSX runtime), `docs/guide/adoption.md` (escape-hatches line). - New `docs/rules/test-only-helper.md`, plus `docs/README.md` rule table, sidebar, `README.md` (rule table, std and safe-ts-vue tables), `CHANGELOG.md` (Added, Changed). ## Verification - `npm run build`: ok. - `cargo nextest run --workspace`: all passed. New tests: `variants` transform and errors, the `panic` fixture, the escape-hatches line. - `cargo clippy -q --workspace --all-targets`: nothing new in the changed code. - `npm run test:std`: 297 passed. New: `tables.test.ts`, `testing.test.ts`, `safe-ts-vue/test/jsx-runtime.test.ts`. - `npm run typecheck` (now with `packages/prelude/test`) and `npm run typecheck:emit`: ok. - `node scripts/docs-typecheck.mjs`, `npm run test:docs`, `npm run test:vite`, `npm run bench:check`, `node scripts/verify-packages.mjs`: all ok. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
std helpers: typed tables, omit, panic, describeError, variants, test helpers, Vue JSX runtime
All checks were successful
Benchmarks / bench (pull_request) Successful in 2m12s
d1295baeb3
- recordOf, keysOf, omit (dict) and indexIn (array): typed tables keyed by a literal
  union, and dropping optional keys without a cast or `delete`.
- panic(message): never: a crash to the checker (the branch ends, nothing propagates),
  counted in check's escape-hatches line.
- describeError for any std error; NumberError gets a `message`.
- The prelude types `filter(Boolean)` to keep what is truthy.
- variants<T>(): an enum's tags, written from the type at build time.
- @evobug_com/safe-ts-std/testing: fixture, testDouble, unchecked, expectPresent; the new
  rule test-only-helper reports them outside test files.
- @evobug_com/safe-ts-vue/jsx-runtime: a typed JSX runtime whose component children
  become the default slot.
- Docs: absent Boolean props, pinned regression seeds, `q`'s instanceof on class instances.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge remote-tracking branch 'origin/main' into up-69
All checks were successful
Benchmarks / bench (pull_request) Successful in 2m39s
077113cd0a
sionzee deleted branch evobug/fb3-std-helpers 2026-11-17 00:09:39 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!69
No description provided.