sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
80.16k stars 4.26k forks source link

Svelte 5 migration script doesn't set expected array type in Props #13572

Open theodorejb opened 1 month ago

theodorejb commented 1 month ago

Describe the bug

My Svelte 4 component has the following props:

export let limit = 25;
export let limits = [10, 25, 50, 100, 200];

TypeScript infers the types as limit: number and limits: number[]. However, the Svelte 5 migration script generated a Props interface with limit?: number (expected) and limits?: any (unexpected). The any type prevents TypeScript from detecting type errors when a user of the component passes in an incorrect prop type (e.g. a string instead of an array of numbers).

Ideally the migration script would generate limits?: number[] in the Props interface to preserve the same type safety as in Svelte 4.

Reproduction

https://github.com/theodorejb/trestable

src/lib/Pagination.svelte is the component with the issue.

Logs

No response

System Info

* svelte-migrate@1.6.2
* @sveltejs/kit@2.6.4
* svelte@5.0.0-next.264
* typescript@5.5.4

Severity

annoyance

Additional Information

No response

benmccann commented 1 month ago

https://github.com/theodorejb/trestable/blob/58977cb95081a4efc6e5d608f8ba825c3b5f6fc7/src/lib/Pagination.svelte#L14