std helpers: typed tables, omit, panic, describeError, variants, test helpers, Vue JSX runtime #69
Loading…
Reference in a new issue
No description provided.
Delete branch "evobug/fb3-std-helpers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 touchjson.rsandCHANGELOG.mdin 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>withoutObject.fromEntries(...) as. Keys are defined as data, so__proto__is a key.keysOf(table)(dict): the typed keys of anas 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 newIndexOf<T>.7.
omit(value, ...keys): done. A copy typedOmit<T, K>. It copies own enumerable keys, symbols included, as a spread does, and neverdeletes. The absence guide has a new "Dropping an optional key" section.8.
panic(message): never: done.ErrornamedPanic.process.exit: the branch ends and nothing propagates. Theassertsfixture covers a catch branch and a module-level call; nouncaught-propagation.N unsafe() block(s), N panic() call(s), N @cache mark(s), ….9. A common
messageon std errors: done.NumberErrorgetsmessage(not a number: "12px").describeError(error)(result) gives one line for aJsonError(path: message), anything with amessage, anErrorPanic(what it holds), anError, or a string.10.
filter(Boolean)narrows: done. A prelude overload onArray/ReadonlyArrayreturnsTruthy<T>[], so(string | false)[]becomesstring[]. A newpackages/prelude/testtype test is part ofnpm 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 withObject.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 ajson-typeerror 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 throwstestDouble: "connect" isn't seton a field it wasn't given, but answers the keys runners andawaitprobe for (then,toJSON, …);unchecked<T>(value);expectPresent(value, what?).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 atest,tests,__tests__or__mocks__directory, or importsnode: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'sJSXtypes.Teleportkeep their children; slot objects pass through. It's built oncreateVNodeplus whathadds, with no cast at the call site.14. Docs lines: done.
prop<Option<boolean>>(Boolean, { default: undefined }).q'sinstanceofon class instances, using the adopter's numbers from the feedback (55 ns inlinetry, 61–65 ns returning the bytes, 80 ns returning theWriter). 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).docs/rules/test-only-helper.md, plusdocs/README.mdrule 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:variantstransform and errors, thepanicfixture, 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 withpackages/prelude/test) andnpm 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