no-null: calls on values declared with a package's type go outside; bench without dev checks #46

Merged
sionzee merged 1 commit from evobug/no-null-package-receivers into main 2026-11-16 13:42:56 +01:00
Owner

From the TwitchRTS comparison report: the server converts SQLite NULLs at the row boundary and had to work around Node refusing undefined as a parameter.

no-null

  • Rows already work: validate<Row>(row) turns the null of an optional field into undefined, also for SQLite's null-prototype row objects.
  • Parameters didn't. statement.run({ note: note ?? null }) was reported whenever the statement was a class field, a parameter or a local, which is how statements are always held. Only a value that came straight from a package import counted as outside code.
  • Now a call counts as outside when its receiver is declared with a package's type, or made from such a value:
    • parameters, locals, this fields and constructor parameter properties;
    • also through Option<…>, Mut<…>, Readonly<…> and … | undefined.
  • The std library's own types don't count.
  • The project's own types still report a null argument.
  • Fixture: null_package_receivers.

Docs

  • The absence guide has a SQLite example: rows through validate<T>, and ?? null in the parameters.
  • no-null.md lists the new case.

Bench

  • npm run bench now runs with SAFE_TS_DEV_CHECKS=0.
  • With the checks on, match measured 1.71× a hand-written switch instead of 0.89×: the misleading result the docs already warn about.

Verification

  • nextest: 182 passed.
  • std tests: 242 passed.
  • npm run build, typecheck, typecheck:emit and the docs build pass.
  • Clippy reports no warnings in the new code.

🤖 Generated with Claude Code

From the TwitchRTS comparison report: the server converts SQLite `NULL`s at the row boundary and had to work around Node refusing `undefined` as a parameter. **`no-null`** - Rows already work: `validate<Row>(row)` turns the `null` of an optional field into `undefined`, also for SQLite's null-prototype row objects. - Parameters didn't. `statement.run({ note: note ?? null })` was reported whenever the statement was a class field, a parameter or a local, which is how statements are always held. Only a value that came straight from a package import counted as outside code. - Now a call counts as outside when its receiver is declared with a package's type, or made from such a value: - parameters, locals, `this` fields and constructor parameter properties; - also through `Option<…>`, `Mut<…>`, `Readonly<…>` and `… | undefined`. - The std library's own types don't count. - The project's own types still report a `null` argument. - Fixture: `null_package_receivers`. **Docs** - The absence guide has a SQLite example: rows through `validate<T>`, and `?? null` in the parameters. - `no-null.md` lists the new case. **Bench** - `npm run bench` now runs with `SAFE_TS_DEV_CHECKS=0`. - With the checks on, `match` measured 1.71× a hand-written switch instead of 0.89×: the misleading result the docs already warn about. **Verification** - nextest: 182 passed. - std tests: 242 passed. - `npm run build`, typecheck, typecheck:emit and the docs build pass. - Clippy reports no warnings in the new code. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
no-null: a call on a value declared with a package's type goes outside; bench without dev checks
All checks were successful
Benchmarks / bench (pull_request) Successful in 2m13s
76739f6351
Node's SQLite takes null for SQL NULL and refuses undefined, but
`statement.run({ note: note ?? null })` was reported when the statement was a
class field (`#insert: StatementSync`), a parameter (`db: DatabaseSync`) or a
local made from one. Only values that came straight from a package import
counted as outside code.

Now bindings, `this` fields and constructor parameter properties declared with
a package's type (also through Option / Mut / Readonly / `| undefined`), or made
from one, are outside receivers. Std types don't count.

Docs: the absence guide shows the SQLite pattern (rows through validate<T>,
`?? null` in parameters); the no-null page lists the new case.

`npm run bench` now runs with SAFE_TS_DEV_CHECKS=0: with the checks on, match
measured 1.71x a hand-written switch instead of 0.89x.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sionzee deleted branch evobug/no-null-package-receivers 2026-11-16 13:42:56 +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!46
No description provided.