Repository navigation
typescript: type a callback parameter from context through an optional callback and without a staged lib - #1740
Merged
Conversation
swapnilpaliwal-sd
requested review from
JaredHLZhang,
Whua689 and
suyashpaliwal26
as code owners
September 29, 2026 02:00
…l callback and without a staged lib `p.then(u => u.m())` left `u` untyped: `then`'s callback parameter is written `((value: T) => R) | undefined | null`, and the rule only looked for a bare function type. Unwrap unions and parentheses to reach it. With no standard library staged (a default index), `xs.map(u => u.m())`, `forEach`, `filter`, `reduce` and `promise.then` had no declaration to read a signature from, so the parameter stayed untyped while `for (const u of xs)` resolved. Type the element parameter of the built-in element callbacks from the receiver's container reference, and `then`'s value from a Promise/PromiseLike reference. Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
…hrough aliases and nested callbacks The no-library route typed a `forEach` / `then` callback parameter from the receiver's type argument by NAME, so a program's own `class Set<T>` or `class Promise<T>`, whose callbacks receive something else, got the type argument as well as its own parameter type. A container name that resolves to a client declaration is no longer read as the built-in. A union of two different function types gives the compiler no contextual type; the union is now looked through only when exactly one member is a function type. The element now travels as a type reference, so the route also reaches `type Users = User[]`, `Alias<User>` over `Array<T>`, a callback over a parameter that was itself typed this way (`xss.forEach(xs => xs.forEach(...))`, `p.then(us => us.map(...))`), and `Map.forEach((value, key) => ...)`. Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
swapnilpaliwal-sd
force-pushed
the
loop/ty-ts-contextual-lambda-param
branch
from
September 29, 2026 03:16
6f0089c to
860f0b6
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TypeScript: type an arrow's parameter from its callback context when the callback is optional (
p.then(u => u.m())) and when no standard library is staged (xs.map/forEach/filter/reduce/…,promise.then,Map.forEach). The type is read from the receiver's container or Promise reference, following type aliases and nested callbacks.class Set<T>/class Promise<T>isn't read as the built-in: its callbacks keep their own parameter type.80-contextual-lambda-paramand81-contextual-lambda-param-no-lib; both agree with tsc 35/35. Controls: userSet/Promise/map/then, union of callbacks, annotated params.