Skip to content

fix: allow transitions to return a function taking a direction argument#3081

Open
Nic-Polumeyv wants to merge 1 commit into
sveltejs:masterfrom
Nic-Polumeyv:fix-transition-return-type
Open

fix: allow transitions to return a function taking a direction argument#3081
Nic-Polumeyv wants to merge 1 commit into
sveltejs:masterfrom
Nic-Polumeyv:fix-transition-return-type

Conversation

@Nic-Polumeyv

@Nic-Polumeyv Nic-Polumeyv commented Jul 18, 2026

Copy link
Copy Markdown

Fixes #2686.

Custom transitions may return a function taking a direction argument — Svelte always calls the deferred config with { direction: 'in' | 'out' } (Svelte 5, Svelte 4) — but the __sveltets_2_SvelteTransitionReturnType shim only allowed TransitionConfig | (() => 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 public TransitionFn type marks direction optional instead; the required form here is deliberate. Because function parameters are checked contravariantly, the required form accepts every shape users can write — () => TransitionConfig as well as callbacks declaring direction required, optional, or widened to 'in' | 'out' | 'both' — whereas an optional-direction shim would still reject the issue's reproduction under strictFunctionTypes (a { direction?: 'in' | 'out' } argument isn't assignable to a parameter typed { direction: 'in' | 'out' }). Existing code is unaffected since () => TransitionConfig remains assignable.

I applied the same change to svelte-shims.d.ts since 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-options diagnostics fixture is extended with a transition returning a direction-taking function; it fails without the shim change and passes with it.

…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-bot

changeset-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4f4b76f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
svelte-check Patch
svelte2tsx Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect types for __sveltets_2_SvelteTransitionReturnType?

1 participant