fix(Data): preserve generic A in TaggedEnum $match arms#6250
Open
milkyskies wants to merge 1 commit into
Open
Conversation
Closes Effect-TS#6249. The direct-form $match(self, cases) overload had A, B, C, D as explicit type parameters, with cases constrained against TaggedEnum.Kind<Z, A, B, C, D>. TypeScript infers Cases and the type params in one pass; when the caller is a generic function (e.g. function f<A>(node: Tree<A>)), A is unbound at inference time and defaults to its constraint, so arms receive unknown instead of A. Reorder the overloads (direct form first) and rewrite the direct form to infer a single const Self extends Kind<Z, any, any, any, any> from self, then derive Cases from Self. The generic A flows in through Self via const inference, and arms get the expected concrete arg type. The curried form (cases-first) is unchanged.
🦋 Changeset detectedLatest commit: 7d05d86 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Type
Description
The direct-form
$match(self, cases)overload onData.TaggedEnum'sGenericMatchershadA, B, C, Das explicit type parameters, withcasesconstrained againstTaggedEnum.Kind<Z, A, B, C, D>. TypeScript infersCasesand the type params in a single pass; when the caller is itself a generic function (e.g.function f<A>(node: Tree<A>)),Ais unbound at inference time and defaults to its constraint, so arms receiveunknowninstead ofA:Match.value(node).pipe(Match.tag(...))works becauseMatch.value<const I>(i: I)capturesIas the concreteTree<A>instance before any cases are typed.Fix
Reorder the two
$matchoverloads so the direct form comes first, and rewrite the direct form to infer a singleconst Self extends Kind<Z, any, any, any, any>fromself, then deriveCasesfromSelf. The genericAflows in throughSelfvia const inference, and arms get the expected concrete arg type.The curried form (
$match(cases)(self)) is unchanged — it still works forpipe+ concrete types as before.Related