__layout `Load` function generated type params are typed as an empty object.
Describe the bug
As the title describes, the Load function type generated by Sveltekit casts the params as an empty object, since the file is at the root of the routes folder.
The problem with that is that since this load function runs on all routes, it does have access to dynamic params when they are present.
I'm not sure what should be done here, but there is definitely a mismatch between the types and what actually happens at runtime.
Reproduction
https://github.com/f-elix/sveltekit-generated-types-error
From this repo, you can run the app locally and go the any url that has two params (ie, '/en/about'). The lang param will be available inside the __layout load function, but the types will show an error if we try to access it.
Logs
No response
System Info
System:
OS: Windows 10 10.0.22000
CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
Memory: 25.93 GB / 39.76 GB
Binaries:
Node: 16.14.2 - C:\Program Files\nodejs\node.EXE
npm: 8.5.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22000.120.0), Chromium (98.0.1108.43)
Internet Explorer: 11.0.22000.120
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.33
@sveltejs/kit: next => 1.0.0-next.301
svelte: ^3.44.0 => 3.46.4
Severity
serious, but I can work around it
Additional Information
No response
Ah, interesting. We probably do want to discourage people from accessing child dynamic parameters, but the current types are definitely buggy. Options:
- the generated types for a given
__layoutinclude all the dynamic parameters for the entire subtree (which, for the root__layout, means all dynamic parameters in the entire app) - we use
{ known: string, [unknown: string]: string }— simpler, less type safety
The first seems preferable to me, though it's definitely a lot finickier to implement
This was fixed recently, the param type should have optional params now for all possible children