Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Fix params and parent data types #5974

Merged
merged 5 commits into from
Aug 17, 2022
Merged

[fix] Fix params and parent data types #5974

merged 5 commits into from
Aug 17, 2022

Conversation

dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Aug 17, 2022

Fixes #5963, closes #5940 (by introducing the event types, which make proxy generation unnecessary if you use them)

  • Tightens up the Params type in most places: It's Partial<Record<string, any>> for the generic type because if you don't type it, you don't know which values are on there. It's also needed in case of layouts where params could be present or not present dependening on the child route. This may be a breaking change for people using strict mode, not having explicitly typed the params generic, and accessing it without checking if it's defined.
  • Adds event types for the load functions and the RequestHandler. Example: export function load(params: PageLoadEvent) {..} - this makes the generation of proxy JS files unnecessary (proxy files only update on file save and when sync/dev is running, which can be confusing) (PageData types don't update to reflect changes to load function(s) #5940)
  • Remove JSONObject because of the type limitations we encountered (LayoutServerLoad return type is not compatible with simple interface object #5963). If we use other serialization-methods later, it would be obsolete anyway
  • Adds generics for the output to the generated load function types, so you can do this: export const load: PageLoad<MyOutput> = ..

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Aug 17, 2022

🦋 Changeset detected

Latest commit: a9984d3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris Rich-Harris merged commit ad0ffa2 into master Aug 17, 2022
@Rich-Harris Rich-Harris deleted the fix-types branch August 17, 2022 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants