Repository navigation
Monomorphize generic overload calls and call generic methods through Pick views - #1511
Merged
Merged
Conversation
…Pick views
- A call that resolves to an overload signature of a generic function or
method with an implementation (`load<T>(k, map: Mapper<T>): Promise<T>;
load(k): Promise<Reply>; load<T>(k, map?) {...}`) monomorphizes the
implementation under the bindings the overload's resolved signature
proves; a type parameter the overload never mentions is unknown, and
parameters the overload omits must be optional in the implementation.
It was refused.
- `view.m(...)` where `view` is a `Pick`/`Omit` view of a program class
and `m` is a generic (or generically overloaded) method extracts the
instance from the view's live receiver and calls the method statically,
instead of a runtime refusal reading the method through the untyped
view.
- Binding inference pairs the arms of `T | Promise<T>` with an
instantiated `R | Promise<R>`, and `unknown | Promise<unknown>` maps to
the checked-dynamic value the checker reduces it to.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Stacked on #1466 (its
Pick/Omitclass views).Calls that select an overload of a generic function or method
Calls that resolved to an overload signature were refused ("calls selecting an overload signature of a generic method"). The implementation now monomorphizes under the bindings that the overload's resolved signature proves for the implementation's type parameters. This is the same structural unification every generic call uses, run against the overload. A type parameter the overload never mentions is
unknown, the checker's answer for an uninferred parameter. The instance's parameters and result are the implementation's under those bindings, because the body was checked against them. The call's arguments and result coerce across, as a non-generic overload call already reconciles with its implementation. Parameters that the overload omits must be optional in the implementation; otherwise the refusal stays.Generic methods through a
Pickviewservices.store.load(...), wherestore: Pick<Store, "load">andloadis generic or generically overloaded, compiled before but failed at run time ("reading 'load' on this native class through an untyped value"), because a generic method has no dispatchable method value. The call now extracts theStoreinstance from the view's live receiver and calls the method statically, as aStore-typed receiver does. A view holding a value of another class throws on the checked extraction.Binding inference for
T | Promise<T>Callback slots shaped
(r) => T | Promise<T>leftTunbound, because the unifier skipped multi-part unions. Each declared part that names a generic target (Promise, an interface, an alias) now pairs with the one instantiated part of the same target, and a single remaining bare type parameter takes the single remaining part. Under anunknownbinding,unknown | Promise<unknown>maps to the checked-dynamic value that the checker's own reduction gives.Evidence
overload-fences.tsnow compiles completely and moves from the diagnostics fixtures to corpus 6496 overload-signatures.pnpm lintandpnpm format:checkare clean.pnpm test:ts7 --baselines-onlypasses; the 6495 baseline is recorded and the moved fixture's baseline moves with it.diagnostics.test.ts: 199/199.Not included
Calling an optional function field after a truthiness check (
p.cb ? p.cb(x) : d) inside such generic bodies needs #1413's narrowed-callback read.🤖 Generated with Claude Code