language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Incorrect types for `__sveltets_2_SvelteTransitionReturnType`?

Open jasonsparc opened this issue 9 months ago • 0 comments

Describe the bug

I created a custom transition that returns a function of type (options: { direction?: 'in' | 'out' }) => TransitionConfig, which Svelte supports. See, https://github.com/sveltejs/svelte/blob/[email protected]/packages/svelte/src/internal/client/types.d.ts#L131

Apparently, in VS Code, I get the following error:

Image

Note that the error will disappear if I use () => TransitionConfig instead.

This shouldn't be the case though, since Svelte supports the optional { direction: 'in' | 'out' } parameter.

Reproduction

Here's a simplified example:

<script lang="ts">
	import { fade, type FadeParams } from "svelte/transition"

	function exampleTransition(node: Element, params: FadeParams = {}) {
		const result = fade(node, params)
		return (options: { direction: "in" | "out" }) => result
	}

	let items = $state(["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"])
	let i = $state(3)
</script>

<label>
	<input type="range" bind:value={i} max="10" />
</label>

{#each items.slice(0, i) as item}
	<div transition:exampleTransition>
		{item}
	</div>
{/each}

The transition:exampleTransition above will be highlighted as an error.

Expected behaviour

As I said before, that shouldn't be the case, since Svelte supports the { direction: 'in' | 'out' } parameter.

System Info

  • OS: Windows
  • IDE: VSCode

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

jasonsparc avatar Feb 15 '25 03:02 jasonsparc