sveltejs / sveltejs/kit

Zero-config type-safety doesn't work properly with `PageData`

Open
#9,799 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

types / typescript
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

The PageData interface is meant to define a set of properties that every page's load function must return as part of its "data" object.

With the new zero-config type-safety, however, it seems like this is not working as expected. The return types of the load functions aren't typed according to PageData, and there will be no errors even if you haven't provided a required property, there's no typing at all:

With this app.d.ts:

declare global {
    namespace App {
        interface PageData {
            meta: {
                title: string;
            };
        }
    }
}

export {};

This +page.ts yields no errors:

export function load() {
    return {};
}

And there are no relevant suggestions, etc:
image

The return type is typed without regard to PageData:
image

It may be worth noting the classic explicitly-typed load functions still work properly in this respect:
image

Reproduction

Described above.

Logs

No response

System Info
System:
    OS: Linux 5.10 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
    Memory: 1.65 GB / 3.84 GB
    Container: Yes
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.1 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.3.0 - /usr/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.0.1
    @sveltejs/kit: ^1.5.0 => 1.15.9
    svelte: ^3.54.0 => 3.58.0
    vite: ^4.3.0 => 4.3.3
Severity

blocking an upgrade

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in app.d.ts and +page.ts, then inspect the zero-config type-safety path described in the issue. The fix is done when a load function returning {} reports the required PageData.meta property while explicitly typed load functions continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.