fix: allow transitions to return a function taking a direction argument#3081
Open
Nic-Polumeyv wants to merge 1 commit into
Open
fix: allow transitions to return a function taking a direction argument#3081Nic-Polumeyv wants to merge 1 commit into
Nic-Polumeyv wants to merge 1 commit into
Conversation
…ment
Custom transitions may return `(options: { direction: 'in' | 'out' }) => TransitionConfig`,
which Svelte supports, but the `__sveltets_2_SvelteTransitionReturnType` shim only allowed
`TransitionConfig | (() => TransitionConfig)`. A function with a required parameter is not
assignable to `() => TransitionConfig`, so valid custom transitions were reported as errors.
Widen the shim's return type to match Svelte's, in both the v4 and v3 shims. The added
transition-options fixture fails without the change.
Fixes sveltejs#2686
🦋 Changeset detectedLatest commit: 4f4b76f The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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.
Fixes #2686.
Custom transitions may return a function taking a
directionargument — Svelte always calls the deferred config with{ direction: 'in' | 'out' }(Svelte 5, Svelte 4) — but the__sveltets_2_SvelteTransitionReturnTypeshim only allowedTransitionConfig | (() => TransitionConfig). A function with a required parameter isn't assignable to() => TransitionConfig, so valid custom transitions were flagged as errors while the parameterless form was accepted.This widens the shim's deferred form to
(options: { direction: 'in' | 'out' }) => TransitionConfig, the same type Svelte 5's runtime uses internally. Note that the publicTransitionFntype marksdirectionoptional instead; the required form here is deliberate. Because function parameters are checked contravariantly, the required form accepts every shape users can write —() => TransitionConfigas well as callbacks declaringdirectionrequired, optional, or widened to'in' | 'out' | 'both'— whereas an optional-directionshim would still reject the issue's reproduction understrictFunctionTypes(a{ direction?: 'in' | 'out' }argument isn't assignable to a parameter typed{ direction: 'in' | 'out' }). Existing code is unaffected since() => TransitionConfigremains assignable.I applied the same change to
svelte-shims.d.tssince the v4 shim's header asks to consider backporting changes; happy to drop that hunk if you'd rather leave the Svelte-3-only shim untouched.The
transition-optionsdiagnostics fixture is extended with a transition returning adirection-taking function; it fails without the shim change and passes with it.