Types the checker could not see: undeclared returns, aliases, receivers behind utility types, optional calls, calls through a slot #123

Merged
sionzee merged 63 commits from return-types into main 2026-11-21 23:32:36 +01:00
Owner

Based on promise-statics (#121), and contains #119, #120 and #121: the diff shown is this piece alone. The open pieces above #118 form one chain, each branch containing the ones below it: #119, #120, #121, #123, then #116 and #122. Merge them in that order.

Combined with the pieces below. Three pieces had each taught the checker that x?.m() is a call, and two had their own way of reading a receiver through Readonly<...> or Option<...>. Here they become one helper and one opener. With #120, const r = repo?.check(id); console.log(r) is a kept Result.

SAFE-TS has no type checker. A rule that depends on what a value is goes by the type that is written. Where none is written, or the written one is a name the checker did not open, the rule said nothing. All of these were silent, with tsc clean:

function count(items: readonly string[]) { return items.length; }   // no declared return
if (count(items)) ...                                    // strict-truthiness: silent; with `: number` it is reported

type Services<R> = { readonly repo: R };
function load(deps: Services<Repo>): string { return deps.repo.load("a"); }   // Repo.load can throw
setTimeout(() => load(deps), 1);                         // uncaught-propagation: silent. Nobody is told.

function check(deps: Readonly<Deps>) { deps.repo.check("a"); }    // a dropped Result: silent (also Pick, Omit, Partial)
repo?.check("a");                                        // silent: an optional call was not followed at all

type Job = Throwing<[], void, JobError>;
const jobs: Record<string, Job> = { a: failing };
jobs[name]?.();                                          // a declared failure, called by key: silent

One answer for every rule

A function's result is known without being declared, when every return is plain: a literal, an operator with one kind of result, a declared binding, a member of a plain value, a call whose result is known (by name, method, getter, static, object-literal member, namespace / default / re-exported import), new of a class, an object or array of plain values, and Vue's ref / computed / reactive and React's useState / useRef / useMemo. Anything else stops the reading: the result is unknown, never guessed. Generic, recursive, overloaded and reassigned functions stay unknown.

A written type is opened the same way wherever it is read: aliases of aliases, imported aliases, generic aliases with their arguments, Readonly / Partial / Required / Pick / Omit / NonNullable / Awaited, the value of a Map or Record, an array's or tuple's item, a promise's value, a union with undefined or null. It stops at conditional and mapped types and says unknown.

Literals keep their type where TypeScript keeps it. const icon = ok ? "icon-a" : undefined; if (icon) is no longer reported: the empty string is impossible there. That was a false positive before this change.

Receivers and slots go through that answer. The failure rules follow a method through any of those written forms of its receiver's type, and failure-contract checks what is put into a slot behind them.

An optional call is a call. repo?.check(id) is followed like repo.check(id).

A call propagates what its callee's written function type declares, however the callee was reached: a Record member or key, a Map's value, an array or tuple item, a local taken out by key. The function type is the contract; a plain function type reached the same way propagates nothing.

New idiomatic rule undeclared-return-type (warning, on with "idiomatic": true): a function whose result the checker cannot read and which does not declare it. Exempt: a body that is a single test (TypeScript infers a predicate only while no return type is written), a function typed by where it is put, a function that returns nothing, and a component. Quick fix where the type can be written.

Tests that hold it

  • Pairs. 69 functions, each written twice: once with the type TypeScript infers declared, once without. Both results are used six ways and must get the same findings; tsc checks that the declared type really is the inferred one. Before this change, 36 of my own 37 held-out pairs differed; now one does, the documented switch without default.
  • Receivers and slot calls. 61 rows: the same method, or the same declared-failure function, reached through each written form, must get what the plain form gets, by name and in an arrow, in the whole-program run and on the editor's path.

On an adopter's project

Nothing is lost. New: 161 undeclared-return-type (warnings), 125 strict-truthiness, and one each of exhaustive-dispatch, negative-member-guard and compare-misses-undefined.

  • The strict-truthiness findings were read one by one: every type is right. They are tests like if (!pending.size), if (dx || dy) and if (bits & mask), where 0 means "none" on purpose. if (bits & mask) stays reported, as it already was where the operand is declared; the rewrite to !== 0 is mechanical.
  • Most of the 161 trace to that checkout's unresolved workspace import; in a 30-finding sample none was a case the checker could have read.
  • No new finding in the failure rules. That project has no class-typed receivers behind Pick<...> and writes no Throwing, so there the routing is proven by the tables, not by findings.

Whole-program pass on its largest entry: 905 ms before, 957 ms after. A name filter keeps the new receiver forms from being resolved where no method of that name matters (100,456 full resolutions at the first attempt, 2,454 now). About 580 ms of that pass is the existing sentinel-error check, which is the target for separate speed work.

What turns red on upgrade

  • With "idiomatic": true: undeclared-return-type warnings, and strict-truthiness on results that were unknown before.
  • A handler assigned to an on... member of a project type behind Mut<...> is now a failure-contract finding, as it already was for the plain type; it was uncaught-propagation.
  • JSON.stringify(f(n)) where f plainly returns a list of numbers is no longer reported.

What stays unseen

  • Packages' declarations are not read: the result of a package's function is unknown unless the checker knows that API.
  • Conditional and mapped types, typeof, indexed access types.
  • A switch without default whose cases all return, and a body TypeScript knows never ends.
  • A computed key on an object type whose members declare different failures.
  • A value typed with a type parameter of its own function.

Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review and acceptance tests) in Claude Code.

Based on `promise-statics` (#121), and contains #119, #120 and #121: the diff shown is this piece alone. The open pieces above #118 form one chain, each branch containing the ones below it: #119, #120, #121, #123, then #116 and #122. Merge them in that order. **Combined with the pieces below.** Three pieces had each taught the checker that `x?.m()` is a call, and two had their own way of reading a receiver through `Readonly<...>` or `Option<...>`. Here they become one helper and one opener. With #120, `const r = repo?.check(id); console.log(r)` is a kept `Result`. SAFE-TS has no type checker. A rule that depends on what a value is goes by the type that is *written*. Where none is written, or the written one is a name the checker did not open, the rule said nothing. All of these were silent, with `tsc` clean: ```ts function count(items: readonly string[]) { return items.length; } // no declared return if (count(items)) ... // strict-truthiness: silent; with `: number` it is reported type Services<R> = { readonly repo: R }; function load(deps: Services<Repo>): string { return deps.repo.load("a"); } // Repo.load can throw setTimeout(() => load(deps), 1); // uncaught-propagation: silent. Nobody is told. function check(deps: Readonly<Deps>) { deps.repo.check("a"); } // a dropped Result: silent (also Pick, Omit, Partial) repo?.check("a"); // silent: an optional call was not followed at all type Job = Throwing<[], void, JobError>; const jobs: Record<string, Job> = { a: failing }; jobs[name]?.(); // a declared failure, called by key: silent ``` ## One answer for every rule **A function's result is known without being declared**, when every `return` is plain: a literal, an operator with one kind of result, a declared binding, a member of a plain value, a call whose result is known (by name, method, getter, static, object-literal member, namespace / default / re-exported import), `new` of a class, an object or array of plain values, and Vue's `ref` / `computed` / `reactive` and React's `useState` / `useRef` / `useMemo`. Anything else stops the reading: the result is unknown, never guessed. Generic, recursive, overloaded and reassigned functions stay unknown. **A written type is opened the same way wherever it is read**: aliases of aliases, imported aliases, generic aliases with their arguments, `Readonly` / `Partial` / `Required` / `Pick` / `Omit` / `NonNullable` / `Awaited`, the value of a `Map` or `Record`, an array's or tuple's item, a promise's value, a union with `undefined` or `null`. It stops at conditional and mapped types and says unknown. **Literals keep their type where TypeScript keeps it.** `const icon = ok ? "icon-a" : undefined; if (icon)` is no longer reported: the empty string is impossible there. That was a false positive before this change. **Receivers and slots go through that answer.** The failure rules follow a method through any of those written forms of its receiver's type, and `failure-contract` checks what is put into a slot behind them. **An optional call is a call.** `repo?.check(id)` is followed like `repo.check(id)`. **A call propagates what its callee's written function type declares, however the callee was reached**: a `Record` member or key, a `Map`'s value, an array or tuple item, a local taken out by key. The function type is the contract; a plain function type reached the same way propagates nothing. **New idiomatic rule `undeclared-return-type`** (warning, on with `"idiomatic": true`): a function whose result the checker cannot read and which does not declare it. Exempt: a body that is a single test (TypeScript infers a predicate only while no return type is written), a function typed by where it is put, a function that returns nothing, and a component. Quick fix where the type can be written. ## Tests that hold it - **Pairs.** 69 functions, each written twice: once with the type TypeScript infers declared, once without. Both results are used six ways and must get the same findings; `tsc` checks that the declared type really is the inferred one. Before this change, 36 of my own 37 held-out pairs differed; now one does, the documented `switch` without `default`. - **Receivers and slot calls.** 61 rows: the same method, or the same declared-failure function, reached through each written form, must get what the plain form gets, by name and in an arrow, in the whole-program run and on the editor's path. ## On an adopter's project Nothing is lost. New: 161 `undeclared-return-type` (warnings), 125 `strict-truthiness`, and one each of `exhaustive-dispatch`, `negative-member-guard` and `compare-misses-undefined`. - The `strict-truthiness` findings were read one by one: every type is right. They are tests like `if (!pending.size)`, `if (dx || dy)` and `if (bits & mask)`, where `0` means "none" on purpose. `if (bits & mask)` stays reported, as it already was where the operand is declared; the rewrite to `!== 0` is mechanical. - Most of the 161 trace to that checkout's unresolved workspace import; in a 30-finding sample none was a case the checker could have read. - **No new finding in the failure rules.** That project has no class-typed receivers behind `Pick<...>` and writes no `Throwing`, so there the routing is proven by the tables, not by findings. **Whole-program pass** on its largest entry: 905 ms before, 957 ms after. A name filter keeps the new receiver forms from being resolved where no method of that name matters (100,456 full resolutions at the first attempt, 2,454 now). About 580 ms of that pass is the existing `sentinel-error` check, which is the target for separate speed work. ## What turns red on upgrade - With `"idiomatic": true`: `undeclared-return-type` warnings, and `strict-truthiness` on results that were unknown before. - A handler assigned to an `on...` member of a project type behind `Mut<...>` is now a `failure-contract` finding, as it already was for the plain type; it was `uncaught-propagation`. - `JSON.stringify(f(n))` where `f` plainly returns a list of numbers is no longer reported. ## What stays unseen - Packages' declarations are not read: the result of a package's function is unknown unless the checker knows that API. - Conditional and mapped types, `typeof`, indexed access types. - A `switch` without `default` whose cases all return, and a body TypeScript knows never ends. - A computed key on an object type whose members declare different failures. - A value typed with a type parameter of its own function. Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review and acceptance tests) in Claude Code.
Open: the rules that judge a value by its type went by the type written on it. A function
without a declared return type gave them nothing (`const n = count(items); if (n)` was silent
while `const n: number` was reported), and must-use-result didn't follow a Result through a
return type written as an alias, nor through `err(...)` in a `?:` branch.

Closed:
- shape.rs reads a function's result off its `return`s when every one is plain (literals,
  `.length`, arithmetic, comparisons, calls of functions whose result is known, `err(...)`,
  `validate<T>`, declared locals, built-in methods of plain values), for declarations, arrows,
  function expressions and methods of `this`, local and imported. Anything else stops the
  reading: unknown, never a union with an unknown part. Generic, recursive (any function met
  again while read), overloaded and reassigned functions stay unknown. Read once per function
  and file. A parameter typed with a function type gives its declared result; `a * f()` with
  a number on one side is a number.
- written.rs: one opener for written types (aliases of aliases, imported, generic aliases with
  their arguments bound where they are written, stopping visibly at conditional / mapped /
  `typeof` / indexed types and at std's own names). must-use-result, catch-on-result and the
  other callee checks use it (`FnInfo::returns_named`, cached per pass); json::value's alias
  shortcut goes through it.
- New rule undeclared-return-type (idiomatic, off unless named): a function whose result can't
  be read off and isn't declared. Exempt: typed by where it is written, returns nothing, a
  single test (TypeScript infers its predicate), a component, test files. Quick fix where every
  return names a type the file can write.

Fixture change: failures/stringify.ts `JSON.stringify(untyped(n))` is no longer reported
(`untyped` returns `[n + 1]`, now read off as number[]); a `new` of a project class keeps the
case reported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open (review of 10f1e996): the read-off result reached only some rules and only bare-name
callees; literals were widened where TypeScript keeps them; q-needs-result-return, sentinel-error
and misplaced-axios-check didn't open aliases; the rule was off unless named.

Closed:
- tests/pairs.rs: one body written twice, with the type TypeScript infers declared (tsc checks it
  is) and without; six uses each; the two must get the same findings. 67 pairs, 0 differ.
- Calls followed however they are spelled: object-literal members, class methods, getters,
  statics and fields (this file's and imported, also through a field typed with the class),
  namespace imports, `export * as`, default exports; `new` of any class.
- Literals keep their literal type in a `const` and a union of returns, widen in a `let`, a
  property and a lone return (`Shape::Fresh`, `Shape::Widen`).
- no-null-check-for-undefined asks the shared shape where its own model can't tell
  (`Want::NoNull`; `null` literals kept apart as `Prim::Null`).
- q-needs-result-return (`Root::Written`), sentinel-error (`SentinelFn::named`) and
  misplaced-axios-check open aliases through written.rs.
- std's `Result` opened as `T | Err<E>` in the evaluator, Vue's `Ref<T>.value`, declared `void`,
  `codePointAt`, a parameter default, `console.*`, `Date` methods, `reduce` with a start,
  `unwrapOr`, Vue's `ref` family with type arguments, `reactive`, `toRef`, a block-bodied
  `computed`, React's `useState` / `useRef` / `useMemo` / `useCallback`; `filter` / `find` over a
  union only where the callback can't be an inferred predicate (or is `x !== undefined`).
- undeclared-return-type: idiomatic, a warning; not in JavaScript files; a component returning
  `items.map(...)` of JSX is exempt. Five doc examples get the type written (package calls the
  checker doesn't read); two idiomatic_rules fixture composables of `useTask` now expect the rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open (review of dff89f13): the failure rules stopped at the first generic alias or utility type
in a receiver's or slot's declared type (`deps: Services<Repo>`, `Readonly<Deps>`,
`ReadonlyMap<string, Repo>`, `pair[0]`, `await p`, `Partial<Port>`, `Record<string, Plain>`), an
optional call's dropped `Result` wasn't one, and an awaited undeclared `async` result was unknown.

Closed:
- project/receivers.rs resolves a declared type through written.rs (generic aliases and
  interfaces with their arguments bound, `Ty::Shape` keeps the binding), the utility types that
  keep members, a `Map`'s `get`, a tuple's item, a `Record`'s and an index signature's value,
  `await` / `.then` of a promise (`Value::Awaited`); cached per pass by type. The analysis records
  a parameter or local with any written type that has type arguments (also a destructured one),
  and follows it by that type rather than its name.
- contracts: slots see through `Partial` / `Pick` / `Required` / `Omit` / `NonNullable`,
  `Record<K, V>` (`Slot::Record`), a generic alias given its arguments (`Slot::Generic`, bound in
  `bound_slot`); `new Map([[k, f]])` / `new Set([f])` are checked against a collection slot.
- `repo?.check(id);` is a dropped `Result`.
- cache.rs (`@cache` through `Held<Catalog>`, `Partial`) and vue.rs's alias table (a generic
  alias's fields) bind type arguments too; both had the same hole.
- shape.rs: an `async` function read off is a promise of its result, `await` opens it (and a
  declared `Promise<T>`).
- tests/receivers.rs: 28 rows (receiver forms, slot forms, written-out cases), each against the
  plain declared form. tests/pairs.rs: 69 pairs (awaited async results added).

Fixture change: entry_points `listen(port: Mut<Port>)` now reads `Mut<Port>` as `Port`, so its two
handlers are `failure-contract` (a slot whose type declares no failure), as with `port: Port`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open after 71e155cc: a method reached through an item of a typed
collection was silent: `repos[0]?.check()`, a local holding `repos[0]`
checked against `undefined`, `const [head] = repos`, `for...of` over a
`Map` or `Set` and over their `values()` / `entries()` / `keys()`, and a
receiver declared `Repo | null`. An element is now resolved to the
collection's item type (an array's or `ReadonlyArray`'s item, a `Set`'s
value, a `Map`'s `[key, value]` pair), an array pattern holds each item
by its index, and `null` leaves a union like `undefined` does. The
receivers fixture's `element` function now propagates `NotFound`, which
was a recorded gap.

Also open: 71e155cc made the pass on an adopter's entry about 100 ms
slower than its start. The pass now builds once the set of member names
any program function or object member can be reached by and answers no
for any other name before resolving the receiver, and memoises a
resolved member per (file, value, name, access). A `Record` slot no
longer makes every member name a slot (a call through `table.a()`
propagates nothing, as through `handlers[name]()`); a function's
declared return type is shared instead of cloned; a class reached
through `Ref` is read without cloning its declaration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A call propagates what its callee's written function type declares, however the callee is reached
All checks were successful
Benchmarks / bench (pull_request) Successful in 3m33s
Tests / test (pull_request) Successful in 7m41s
bac47a019c
Open after 98443f43: removing the Record name wildcard to save time
silenced a call the starting commit reported (`jobs.a?.()` with
`jobs: Record<string, Job>` and `type Job = Throwing<[], void,
JobError>`), and next to it calls through a declared function type
were silent wherever the callee was reached other than by a member
name some declared type writes: `jobs[name]?.()`, a local taken out by
a key and checked, `table[key]()` on an object type,
`byName.get(name)?.()`, `list[0]?.()`, a module-level `const job: Job`
called by name.

What closes it: the analysis records a call of a value no name is
written for (an item read by a key, what a call hands back) as a call
through that value, and holds a local taken out by a key. The
whole-program pass asks the slot reading, without a name filter, for
every call it can't tie to a body: a record's or index signature's
value by any name or key, an array's item by index or key, a Map's
`get`, an array's `at` / `find` / `pop` / `shift`, a tuple's position,
a computed key of an object type whose members declare the same
contract. A tuple slot checks what is put into it item by item; an
interface or object type that is only an index signature is a record.
A plain function type still propagates nothing; a mapped type stays
unknown. A new table test (24 rows) holds each form, by name and in an
arrow, in the whole-program run and on the editor's path, to the plain
`job: Job`.

The name filter is replaced by two exact gates: the fallback from a
receiver's class runs only for a member some class declares with a
function type, and an interface's members are read without cloning
the list each time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open: each rule that asks "did A happen before B on some path" had its own walker with
its own idea of branches, loops and exits (number-parse-nan and not-found-index took source
order, stale-read an ancestor walk, holders and bounds their own exits).

Closes the first step: flow.rs builds a graph per function body on request (if, ?:, &&/||/??
as jumping code, optional chains, loops with back edges, switch fall-through, labelled
break/continue, return/throw, try/catch/finally with a finally copy per way out; nested
functions are one point; await/yield end their block) and a bitset forward data-flow driver
(Meet::Any / Meet::Every, replay). number-parse-nan decides "used before a check" on it:
identical on the adopter; three fixture cases the source-order walk got wrong (a check in the
other branch, a use on the next loop round, a new value assigned).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
What was open: each of these passed tsc strict, `safe-ts check --idiomatic --deny-warnings`
and oxlint with the preset, and none was counted or ratcheted.

- `// @safe-ts std` / `// @safe-ts legacy`: one comment turned every rule off for a file (and
  `std` made its functions count as never failing for callers), and nothing said who may write
  it. Now a marker counts only in files the nearest "safe-ts" package.json lists under
  "trustedFiles" / "legacyFiles" (patterns as in "overrides", relative to it). Anywhere else it
  is an `unlisted-marker` error at the marker and the file is checked, transformed and followed
  as if it weren't there: check, the editor, the oxlint plugin, the Vite plugin and the loader
  all go through `Project::markers_allowed` (part of the analysis cache key). Library code in
  node_modules keeps its markers. `safe-ts check` prints, per package.json, the lines that list
  every marked file it found. The repository's packages, the demo, the fixtures and the docs
  examples list theirs.
- `eslint-disable*` / `oxlint-disable*` comments were counted nowhere, and silenced the oxlint
  plugin. Now all are counted; a blanket one or one naming a `safe-ts/` rule is reported by the
  new `no-lint-suppression`, on the directive's name inside the comment, where oxlint's own
  directive ranges don't reach (measured: a block directive applies from its comment's end, a
  `-line` one to the code before the comment). A named rule of another linter is only counted.
- `declare const | let | var | function | class | enum | namespace`, `declare global`,
  `declare module "..."` and the project's own .d.ts files were casts with no `as`. Now they
  are counted, the CLI checks the .d.ts files under the entries' directories (as the editor and
  oxlint already did), and the new `no-unchecked-declare` reports what asserts a value nothing
  checks (a type other than `unknown` or one admitting `undefined`, functions, classes, enums,
  required members added to a built-in or in a package augmentation, values added to a project
  module, `declare module "x";` with no body).
- `defineSanitizer(...)` was not counted; now it is, also through `export *` and renamed
  re-exports in project modules (and so are re-exported `trust()` and `panic()`).

The three counts are in the summary line, `--json --summary` and the baseline, and a test holds
the three together. An old baseline without the new keys loads; a missing count is 0, so the
gate fails once with a note until it is written again.

Soundness corpus: four new classes (unlisted std marker, unlisted legacy marker, a declared
value, a member declared on Array) that escaped before and are rejected now; the corpus project
lists no marker files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open: a value used again after an operation used it up passed every gate (a generator or an
array's iterator iterated twice, an ArrayBuffer used after transfer() or a transfer list, a
Response body read twice, a locked stream, a closed WebSocket, MessagePort, FileHandle or
readline interface), and must-use-result only saw a Result dropped as a statement, not one kept
in a local and only logged.

Closes:
- use-after-consume (an error, on by default), on the flow layer: a fact per operation site,
  set where it runs, cleared by a new value or releaseLock(); a second solve on every path
  words "on one path". Which operations consume, what state they leave and which uses fail is
  data: a `consumes` section in ecmascript-api.json, browser-api.json and node-api.json
  (compiled in; a platform's findings kept where its pack is on), demonstrated on Node
  (ecmascript/consumes.test.ts, packages/feature-*/test/consumes.test.ts) and, for Worker and
  the global postMessage, in Chromium, Firefox and WebKit (test:browsers). The packs' safe
  versions count as the member they stand for. A view made on a buffer before the transfer
  reads the detached buffer (reported); one made after throws where it is made.
- must-use-result: a call kept in a local (kept.rs) that, on some path to an end after the
  last code that looks at it, nothing looks at, or that a new value replaces first; the
  whole-program pass reports the ones whose function returns a Result. Logging and string
  conversion aren't looking; handing it on, storing it, capturing it, returning it are. An
  exception and an early return before the look aren't drops; a short-circuit test of several
  counts for each.
- Soundness corpus: one-shot-generator-reused and use-after-consume-arraybuffer come off
  escaping.txt; new classes response-body-read-twice and result-kept-only-logged (both escape
  at the starting commit, both rejected now).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open: the new rule, the kept-Result part of must-use-result, the consumes format and the paths
number-parse-nan now follows were undocumented, and two pages said number-parse-nan takes source
order.

Closes: docs/rules/use-after-consume.md (idiomatic forms first, what it can't see),
must-use-result's "A Result kept in a local", docs/guide/flow.md, the `consumes` format in the
libraries guide (and a pointer from the built-ins guide), number-parse-nan's and
not-found-index's pages, README (rules table, known gaps), docs index and sidebar, the errors
guide, CHANGELOG (Added: the rule and the flow layer; Changed: must-use-result and
number-parse-nan, with what to write instead), and the migration skill's patterns and tool gaps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open: `Result<T, E>` is `T | Err<E>`, so a `Promise<Result<T, E>>` is a `Result` too. `q`,
`isErr`, `isSome`, `unwrapOr`, ... accepted a promise nobody awaited and answered "no error";
TypeScript and the checker let a promise through as text, under `!`, `||`, `??`, in a
comparison with `undefined`; an async predicate handed to `filter` (or to a project function
declared `(x: T) => unknown`) kept every item; and an async call that can't reject, dropped as
a statement, let the caller go on with nothing reporting it.

Closed:
- std: the functions that read a value refuse a promise in their types (`PromiseCheck`,
  `AwaitFirst`: "this is a promise: `await` it, then pass the value"), via a last type
  parameter whose undecidable default falls back to its constraint, so generic code and a
  `Result<Promise<T>, E>` written on purpose still compile. Checked under TypeScript 7 and 5.9,
  and over an adopter copy: nothing new stops compiling.
- `promise-as-value` (error): those calls, the places TypeScript lets a promise through, an
  async callback handed to a built-in that reads its answer right away (the map's new
  `callbacks`, tested on Node; the ones lib types are left to tsc), and to a project function
  whose parameter type lets one through and whose body reads it. Quick fix: Add await.
- `floating-promise` (warning): a dropped promise that can't reject; never the same call as
  `floating-rejection`; not the last statement of an event handler or timer.
- Soundness corpus: five classes (promise-read-as-result, promise-read-as-text,
  floating-promise-ordering, async-callback-read-right-away,
  async-callback-read-by-project-function), all escaping at e8029782, all rejected now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open: npm run typecheck failed on packages/pack-kit/consumes.ts (a DOM-only type name, and a
check TypeScript took for always true). Closes: a structural type for the read result, and the
demonstration typed as possibly missing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
What was open after 25d3ef37, and what closes it:

- A hatch was counted only when called by its imported name: `r.trust(x)`, `const t = trust;
  t(x)`, `(0, trust)(x)`, `trust.call(...)`, `r.unsafe(...)`, `stop = panic` counted nothing, so
  `export const forged = r.trust<T>("no")` passed the baseline uncounted. Now one pass over the
  semantic references of every binding that may hold one (named and namespace imports,
  destructuring, dynamic `import()`, prelude names; hatch_refs.rs) classifies each use: a call,
  `.call` / `.apply` / `.bind`, a copy followed to its own uses (an exported copy counts once),
  and any other use counted (handed on, re-exported, a std namespace used whole: fail closed).
  Types (`typeof trust`) don't count. The whole program decides which imports are hatches,
  through re-exports, and counts `export { x as y } from` of one.
- With std or the Vue package linked into a workspace, `defineSanitizer` counted 0: the
  resolver calls those files the project's. Now the package.json that owns the defining file
  says what it is, and a SAFE-TS package's own files aren't counted as uses.
- vue-tsc's `<!-- @vue-ignore -->`, `<!-- @vue-skip -->` and `<!-- @vue-expect-error -->` were
  neither reported nor counted. Now `no-ts-suppression` reports ignore, skip and a reasonless
  expect-error; ignore counts with @ts-ignore, expect-error with @ts-expect-error, skip as the
  new `vueSkips`.
- A disable of an oxlint rule the preset makes an error (`no-eval`, `no-proto`, ...) passed
  silently: those rules are how SAFE-TS bans the constructs. Now one without `-- reason` is
  reported by `no-lint-suppression`. The same at config level: `.oxlintrc.json` next to the
  package.json (JSON with comments) is read, and a config not extending the preset, a preset
  rule turned off or down in "rules" or "overrides", and "ignorePatterns" are named as weakened
  settings, which the baseline ratchets.
- `declare value: string` in a class was silent while `value!: string` is a cast. Now it is
  reported by `no-unchecked-declare` and counted with the ambient declarations.
- Docs that teach a `declare` form are checked with the rule on (`declares` fence word), and
  say what the rule asks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open (review): a buffer transferred through its view (`[pixels.buffer]`, `pixels.buffer.transfer()`)
left the views unreported; `maybe?.transfer()` wasn't seen; `const same = buf` was a stranger;
and the browser and Node `consumes` were compiled into the checker, so a third-party pack (or a
project's own) couldn't declare one, and a pack's version could disagree with the checker's.

Closes:
- A pack's `consumes` is read from its safe-ts.json with the rest of the pack (Manifest::consumes;
  the browser and Node packs copy theirs from their API maps when safe-ts.json is generated, and
  the manifest tests keep the two equal). Only the language's map stays compiled in. A pack's
  safe versions come from its manifest's `safe` refs. What a pack gets wrong (an entry described
  differently from an earlier pack, an operation on a state nobody describes, a section that
  isn't one) is a setup warning and that entry is left out (consumed::for_packs, unit tests).
  Fixture consume_pack: a tiny third-party pack with a one-shot cursor.
- Groups (Cx::group): a second name (`const same = buf`, neither reassigned) is the same value;
  a typed array or DataView is a view on a buffer (the one it was made on, `x.buffer`, or its
  own); `x.buffer` in a transfer list or `x.buffer.transfer()` uses up every view of the group.
  `x.buffer.detached` is asking, not using. A reassigned `let`, a property or a destructuring
  isn't followed.
- The flow layer keyed points by span alone, so a call inside an optional chain shared its key
  with the chain (`a?.b()`), and an expression statement without `;` with its expression: points
  are keyed by span and kind now (flow::PointKey). That is what hid `maybe?.transfer()`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Weakened lint settings are named by .oxlintrc.json, the file that sets them
All checks were successful
Benchmarks / bench (pull_request) Successful in 3m54s
Tests / test (pull_request) Successful in 7m48s
6577df1a9a
The check listed `oxlint.rules no-eval off (package.json)`: the setting lives in the
`.oxlintrc.json` beside it, and that is where a reader has to look.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Kept Results beyond a bare call; the cheap test before any graph; the layer's path table
All checks were successful
Benchmarks / bench (pull_request) Successful in 3m57s
Tests / test (pull_request) Successful in 8m6s
9a540ef57e
Open (review): `const r = flag ? save(1) : save(2)` and `const [a, b] = await Promise.all([...])`
weren't seen as kept Results; the kept-Result analysis built a graph for one function in five on
the adopter's largest entry (2,561 of ~10,500) and use-after-consume for 539, mostly for calls
that can't matter; and the layer was held only by ten unit tests and the rules' fixtures.

Closes:
- Kept: each call of a `?:` / `??` / `||` / `&&` / parenthesised / awaited initialiser, and each
  element of an array destructuring of `Promise.all` / `allSettled` over a list written in
  place, in the binding at its place (fixtures). `const { result } = pair()` isn't (only
  `pair`'s return type says what `result` is).
- The cheap test first. Kept Results: the local pass only lists the kept calls (no graph),
  after two syntactic tests (a const looked at unconditionally by the very next statement; a
  call whose callee the file shows returns a plain type, or a method of a value declared with
  one); the whole-program pass keeps those whose function returns a Result and only then
  parses the file again and builds graphs for them (`unsafe(...)` / `parseJson` stay local).
  use-after-consume: a function gets a graph only if an operation there would use a binding
  up (`Array.from(list)` of an array doesn't); the generator walk runs only in a file with a
  `function*`. On the adopter's `apps/client/src/start.ts`: 3,119 graphs before (2,561 kept,
  539 consumed, 19 number-parse-nan), 40 after (21, 0, 19).
- flow::tests::path_cases: 39 shapes with their answers on some / every path, independent of
  any rule (labelled break and continue, do...while, a loop's update clause, for await,
  continue in try/finally, finally after a return, nested finally, switch with default in the
  middle and falling into it, && / || in a statement and a test, ?:, ??, ||=, optional calls,
  yield and await between, reset, an exception into catch, nested functions, unreachable code).
- Docs: the libraries guide says a pack's `consumes` is read from its safe-ts.json (and the
  manifest example shows it); use-after-consume's page covers views, second names and optional
  calls; must-use-result's covers branches and Promise.all; README gaps, CHANGELOG, tool gaps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open after f10ffd50:
- `promise-as-value` took any `filter` or `forEach` for the built-in's, also on a receiver whose
  type says otherwise (Node's `Readable`, whose `filter` awaits; a class of the project).
- `floating-promise` exempted the last statement of a timer or listener but not of a hook, so
  the verdict depended on which callers the checker knew.
- Missed: an optional call dropped (`hooks?.flush()`), a call through a declared function type
  (`flush: () => Promise<void>`), `const flags = ids.map(async ...)` read through the `const`,
  an assertion on a promise (`expect(p).toBeTruthy()`, `assert.ok(p)`); a receiver declared
  `Option<C>` wasn't followed to `C`'s methods by any rule.
- std's ten `@ts-expect-error` (TS2344) directives were held by one compiler only.

Closed:
- A method is the built-in's by the receiver's written type (array, typed array, Map, Set,
  iterator, DOM list; through an alias, a declared return type, a chain, across files); another
  written type isn't; an unwritten one is taken for the built-in (policy on the rule page).
- `floating-promise` reports a statement wherever it is; an arrow's value, a function passed by
  name and a Vue template's handler aren't statements.
- The misses above; `Option` / `Readonly` / `Mut` / `NonNullable` receivers are followed
  (entry_points: `port: Mut<Port>` now gets `Port`'s verdict, failure-contract).
- `typescript-versions.test.ts` compiles std, a consumer project and awaited.check.ts with
  TypeScript 7 and 5.9 (the one vue-tsc-tools installs); explicit type arguments that are type
  parameters are documented with the message users see and the fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mapped promises read as values: a plain arrow that returns one counts like an async one
All checks were successful
Benchmarks / bench (pull_request) Successful in 3m38s
Tests / test (pull_request) Successful in 12m49s
4eed7ea98b
`ids.map(async (id) => allowed(id))` read through `.some(Boolean)` was reported;
`ids.map((id) => allowed(id))` was not, although the list holds the same promises.
The callback forms the other checks already know (async, by name, an arrow whose body
is a call) now all apply here.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Conflicts, all kept from both sides: `analyze_file_with` / `analyze_vue_with` / `analyze`
take both the `consumes` table and the `MarkerPermission`; `Project::analyze_text` passes
both; `FeatureSet` has `consumes` and the marker lists / oxlint weakenings; the rule list,
the sidebar (no-lint-suppression, unlisted-marker and no-unchecked-declare under Ignore
comments, use-after-consume under Correctness), the module list and the CHANGELOG's Added
and Changed entries hold both pieces'. `kept_results` and the hatch-counting functions of
project.rs sit side by side.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts, all kept from both sides: ecmascript-api.json gets both new sections (`callbacks`
and `consumes`, merged as JSON: each side only added its own key); package.json takes
`test:std` from this side (vue-tsc tools for the TypeScript-versions test) and `test:browsers`
from the other (the browsers' consumes test); the soundness class list imports both new
groups; the migration skill has both sections ("A promise used as its value", "A value used
after it was used up") and census.mjs both pointers; the CHANGELOG's Added and Changed keep
every entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open: with no-unchecked-declare (escape-hatches-2) in the chain, `declare function
openStream(): Readable;` in the receivers fixture is reported, as every other fixture stub's
`declare` is. Closes: the expectation written on it, as on the other fixtures' stubs; the
stub stays, since what the fixture shows is a call returning a package's Readable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts, kept from both sides: `FnInfo` gets `returns_promise` and `returns_named` (both
computed where the function is declared; `names_a_type` and `is_promise_type` side by side),
the rule list, `.gitignore`'s fixture node_modules (consume_pack and return_types), the
meaning tests (one entry for `undeclared-return-type`, one for `floating-promise`), the
migration skill's tool gaps (the hatch counts and no-unchecked-declare from one side, the
strict-truthiness wording that names undeclared-return-type from the other), and the
CHANGELOG. must-use-result's page keeps the new "A Result kept in a local" section and the
rewritten "What the rule can't see" (aliases are opened now; the kept-Result sentences after
it stay). entry_points: both sides made the same expectation change; this side's comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Open after the merge: three mechanisms read a receiver through `Option<C>`, `Readonly<C>`,
`Mut<C>`: the whole-program opener (`written_ty`, which knew `Readonly`, `Mut` and the
utility types, but not std's `Option`), and two analysis-side unwraps from the promise rules
(`named_class` in `annotated_class`, an early return in `receiver_type`), which only the
receivers of imported classes reached. And "an optional call is a call" was written three
times: the failure rules' and the promise rules' statement walkers each unwrapped
`repo?.check(id)` themselves, and the kept-Result collector didn't, so `const r =
repo?.check(id); console.log(r)` dropped the error unseen.

Closes:
- The opener reads std's `Option<C>` as `C` (as `C | undefined` already was), and a std name
  is see-through also where std is code of the project (`written::is_std`); a project type of
  that name still isn't. The two analysis-side unwraps are gone: a binding written with type
  arguments is followed by its written type (`record_receiver_binding`), and the two places
  that asked `instance_of` alone now ask that first too: a call through a second name
  (`const same = fixed; same.run()`, spelling.rs) and a binding handed to a slot
  (`given_of`). Receiver table: two rows, `Option<Repo>` and `Option<Deps>`; spellings
  fixture: `Readonly<Handlers>` and `Option<Handlers>` through a second name.
- `analyze::as_call`: the call an expression is, also optional; the statement walkers of
  the failure rules and of floating-promise, and kept.rs, all ask it. kept_results fixture: an
  optional call kept and only logged (reported), and one checked (silent).
- Docs: must-use-result (optional calls kept; `Option` and `Mut` in the written forms),
  uncaught-propagation, the CHANGELOG entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ambient declarations test: a neutral member name in the sample
All checks were successful
Benchmarks / bench (pull_request) Successful in 4m9s
Tests / test (pull_request) Successful in 9m13s
6e1cc600bc
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Merge the chain below: a neutral member name in the ambient declarations test
All checks were successful
Benchmarks / bench (pull_request) Successful in 4m19s
Tests / test (pull_request) Successful in 9m56s
259c12be10
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
A dropped promise that holds a Result gets one finding, not two
All checks were successful
Benchmarks / bench (pull_request) Successful in 4m14s
Tests / test (pull_request) Successful in 9m10s
7c841c8442
`load();` with `load(): Promise<Result<...>>` was both `floating-promise` and
`must-use-result`. The dropped `Result` is the finding; awaiting it and looking at it
answers both, so `floating-promise` leaves the call to that rule, as it already does
for the rules about failures.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Merge the chain below: one finding for a dropped promise that holds a Result
All checks were successful
Benchmarks / bench (pull_request) Successful in 4m29s
Tests / test (pull_request) Successful in 10m37s
c539bc1dfe
Co-Authored-By: Claude Fable 5.2 <[email protected]>
sionzee changed target branch from sentinel-values to promise-statics 2026-11-21 20:38:48 +01:00
sionzee changed target branch from promise-statics to main 2026-11-21 23:31:06 +01:00
Merge main
All checks were successful
Benchmarks / bench (pull_request) Successful in 2m42s
Tests / test (pull_request) Successful in 8m47s
4b9cc7e00b
Co-Authored-By: Claude Fable 5.2 <[email protected]>
sionzee deleted branch return-types 2026-11-21 23:32:36 +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!123
No description provided.