Skip to content

Conversation

@dummdidumm
Copy link
Member

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

- T extends Record<string, any>  allows T to be an array, Record<string, known> doesn't, closes #6261
- RequestHandler generic is partial now to align with the other types and prevent type conflicts
- generate definite set of route params, this is more correct and makes hover info better
@changeset-bot
Copy link

changeset-bot bot commented Aug 25, 2022

🦋 Changeset detected

Latest commit: c71c10d

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 ed331d4 into master Aug 25, 2022
@Rich-Harris Rich-Harris deleted the type-tweaks branch August 25, 2022 17:24
* It receives `Params` as the first generic argument, which you can skip by using [generated types](/docs/types#generated-types) instead.
*/
export interface RequestHandler<Params extends Record<string, string> = Record<string, string>> {
export interface RequestHandler<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dummdidumm shouldn't this be

export interface RequestHandler<
	Params extends Record<string, string> = Record<string, string>
> {
	(event: RequestEvent<Partial<Params>>): MaybePromise<Response>;
}

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why exactly?

Copy link
Contributor

@ivanhofer ivanhofer Aug 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you want to makr all params of the event as optional

Here is an example that demonstrates the issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. No it's working as intended. What you pass for the generic should be applied as-is, i.e. required params should be passed and can be expected to exist. It changes to Partial<..> so that in case you don't type the generic you can't just access the park without checking if it exists (in strict mode)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I get it. Thanks for the explanation. Didn't knew this trick before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typescript doesn't show an error when trying to return an array in load function

4 participants