A promise where a value is read: refused by the std types, promise-as-value, floating-promise #121
Loading…
Reference in a new issue
No description provided.
Delete branch "promise-statics"
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?
Based on
flow-consumed(#120), and contains #119 and #120: 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. The API map now carries this piece's
callbackssection next to #120'sconsumes. A dropped call whose promise holds aResultgets one finding,must-use-result, not two.Result<T, E>isT | Err<E>, a plain union, so aPromise<Result<T, E>>is itself a validResult: itsTis the promise. Everything that inspects aResulttherefore accepted a promise somebody forgot toawait, and answered "no error". These passedtscstrict,safe-ts check --deny-warningsand oxlint:What changes
The std types refuse a promise.
isErr,isSome,isPanic,q,unwrapOr,mapErr,describeError,isJsonErrandexpectPresentno longer compile when handed one.tscsays: Property '"this is a promise:awaitit, then pass the value"' is missing in type 'Promise<...>'. A genericResult<T, E>still compiles, and aResult<Promise<T>, E>written on purpose with itsEnamed is let through.New rule
promise-as-value(error), for the placestscstays silent, with a quick fix that addsawait:tscif (p),p + 1,p.length,switch (p)isErr(p),q(p)and the other std readers`${p}`,!p,p ?? x,p === undefined,String(p),JSON.stringify(p)filter/some/every/find*,forEach,new Promise(async ...), areducethat doesn't await its accumulatoritems.map(async ...)read as values (.filter(Boolean),.some(...)), also through aconstexpect(p)without.resolves/.rejects;assert.ok(p)Which built-ins read their callback's answer at once is data in the ECMAScript map, with a test on the running engine. A method counts as the built-in's when the receiver's written type says so: Node's
Readable.filter(async ...), which awaits its predicate, is not reported.New rule
floating-promise(warning). A promise dropped as a statement, when it cannot reject (floating-rejectioncovers the ones that can).await,return, a chain, orvoidsays it is on purpose. It is reported wherever the statement is; the value of an expression-bodied arrow, a function passed by name, and a Vue template's inline handler are not statements and stay silent.What turns red on upgrade
isErr<T, E>(r)orunwrapOr<T, E>(r, fallback)inside a generic function stops compiling, with Argument of type 'Result<T, E>' is not assignable to parameter of type 'NotAPromise<CheckResult<T, E>, Result<T, E>>'. The fix is to drop the type arguments. The message does not mention promises, so it is spelled out in the changelog and on the rule's page.voidbecomes a warning.On an adopter's project: no new findings from either rule, and nothing stops compiling under real
tscwith the changed std. That project already writesvoidon its 44 deliberate fire-and-forget calls; all were read, and none is an ordering hazard.Evidence
@ts-expect-error, in source that every consumer'stsccompiles. I type-checked a consumer project against it under TypeScript 5.5.4, 5.6.3, 5.7.3, 5.8.3, 5.9.3, 6.0.3, 7.0.2 and 7.1.0-beta: all clean, the promise calls refused in every one.npm run test:stdnow compiles a consumer under both TypeScript 7 and 5.9, so a compiler that stops raising the error fails the test instead of every adopter's build.ids.filter(allowed),q(loader())withconst loader = load); optional calls (hooks?.flush()), calls through a typed field, and a constructor that starts work are reported; a promise kept forPromise.all, pushed to a list, compared by identity or returned is silent.What stays unseen
letor a field.floating-promisefor package and platform calls.console.log(p)and other calls that merely print or pass the promise on.Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review, acceptance tests and one fix) in Claude Code.
asyncone.oxlintrc.json, the file that sets themOpen (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]>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]>Resultgets one finding, not twodeclareis a cast #119Resultkept in a local #120this, parts handed out, kept copies, wider aliases, loans alive at once #122