Skip to content

Migration: Add correct type for bind:this of Components when using the migration script #13491

Closed
@FoHoOV

Description

@FoHoOV

Describe the problem

In svelte 4 when typing the bind:this we used this:

<script lang="ts">
	import Component from "./Component.svelte";

	let comp: Component | undefined = undefined;

	onMount(()=>{
		comp.sayHi();
	})
</script>

<Component bind:this={comp} />

After running the migration script nothing changes whilst it should be:

<script lang="ts">
	import Component from "./Component.svelte";
	import {onMount} from "svelte";

	let comp: ReturnType<typeof Component> = undefined;

	onMount(()=>{
		comp.sayHi();
	})
</script>

<Component bind:this={comp} />

Describe the proposed solution

Use ReturnType<typeof X> or use the utility type in #13441 which makes bind:this type forward-compatibale - easier to change internally without requiring change on the comsumer code.

here is the REPL

Importance

would make my life easier

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions