-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[fix] type tweaks #6271
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] type tweaks #6271
Conversation
- 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 detectedLatest commit: c71c10d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
| * 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< |
There was a problem hiding this comment.
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>;
}?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why exactly?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
Typescriptdoesn't show an error when trying to return an array inloadfunction #6261Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. All changesets should bepatchuntil SvelteKit 1.0