-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add generic type for session #1791
Conversation
🦋 Changeset detectedLatest commit: 0548e43 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 |
@dummdidumm GrygrFlzr pointed out on Discord that this PR doesn't help with this:
I wonder if there's anything we could do here? i.e. update your own ambient type per project, something like this:
If that's the only solution, perhaps it should be documented? |
That seems like a useful addition, but I wouldn't add it to the site docs, only to the jsdoc in the |
Odd. I just tested this in the example project. In a component (with a typo:
This doesn't work, VSCode and build / lint scripts think session in the component is
However, if I remove the reference it all works and VSCode picks up the error. Does this line actually need to be included?
|
Yes it needs to be included, else other imports from |
I'm prob missing something. Why doesn't SvelteKit propagate the return type of I have // src/hooks.ts
export function getSession(): Record<string, string> {
// ...
return session
} yet when I import import { session } from '$app/stores' it has type (alias) const session: Writable<any> |
Previously, in Sapper, we could use generics to ensure our session type was used correctly:
E.g. if I had a session type that was
{ foo: string; }
This PR adds the same generic support in
getStores
as well as a 3rd param in the generic forLoadInput
SvelteKit:
Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts