Skip to content

Feat : [Svelte5] Generate a PageProps into $types #12726

Closed
@adiguba

Description

@adiguba

Describe the problem

Sveltekit generate a type PageData for each +page.svelte, which allows to properly type the data prop :

<!-- Svelte 4 -->
<script lang="ts">
    import type { PageData } from './$types';
    
    export let data: PageData;
</script>

It's fine with Svelte 4, but with the new syntax in Svelte 5 we have to define an additional type for the $props runes :

<!-- Svelte 5 -->
<script lang="ts">
    import type { PageData } from './$types';

    type Props = {
        data: PageData;
    }
    
    let {
        data
    } : Props = $props();
</script>

Describe the proposed solution

The generated $types should include a new type PageProps, in the following manner :

export type PageProps = {
    data: PageData;
}

Which would allow us to write directly :

<!-- Svelte 5 -->
<script lang="ts">
    import type { PageProps } from './$types';

    let {
        data
    } : PageProps = $props();
</script>

Alternatives considered

Rewrite the $props() type on every page...

Importance

nice to have

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions