-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
initial types testing #4124
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
initial types testing #4124
Conversation
|
Oooh this is nice! Agree that we should keep it simple. Regarding your questions:
|
For the identity function, yeah more or less what you explained there. I haven't found a nice solution yet but I did find one and it's mostly for #1997, Because we're asking users to type the functions themselves, we also need them to pass in the generics for type-checking to properly work like A code example for the above // src/routes/endpoint.ts
import { request } from '@sveltejs/kit';
export const get = request(({ /* usual destructuring */ }) => {
// usual code handling
// usual return
return {
// ...
};
}); It would abstract all the complicated type handling in that A code example with config // somewhere in kit source code
export const config = (v: Config) => v;
// in user's svelte.config.js
import { config } from '@sveltejs/kit';
export default config({
// ... autocomplete here
}) We could even make the |
This looks great. One downside of the identity function approach is we lose the ability to do this: #4120 |
I also think that an identity function obscures what's actually happening (you can't tell it's just an identity function by looking at it), and risks adding confusion ("why does this person's tutorial use this funny |
Always fascinated to see the analogies that comes up around Rich, and this is probably the most amusing one so far. Yeah, those are some solid arguments, especially the different approaches that ends up taking away the consistency of a SvelteKit application between codebases and tutorials. We'll keep them as is then, I think we can still strongly-type them in some ways. |
LGTM. |
Now that we're more or less settling in on our types structure, a typings test would make sure that we have them reliable and don't break on some changes that might've slipped through. These are just basic tests for now but I've made sure to include some of the cases where it's prone to breakage. Outstanding issues will be dealt on later.
P.S. @dummdidumm we've talked about using
tsd
then, but I have yet to find a complex case where we'd need those fancy APIs with a huge dependency tree as well. We can always add and adjust the test later if we need to, and I think this should be enough for most of our cases right now.Some questions TBD:
undefined
values causes error, might be an oversight but it's not exactly part ofJSONValue
either, but I'm pretty sure we'll have to change this behaviorRequestHandlerOutput
. A proposed solution and probably the easiest one would be to export an identity function so we can work more freely with our types. I haven't found a good strong problem and solution pair that needs this specific approach for it to work though, but one of the nice things that would be apparent with identity functions would be that (assuming VSCode as the base case here) users—both JS/TS—wouldn't need to manually type their config,load
, or request handlers anymore. I'm not too strong on this for now, but it would be really nice to have.Please don't delete this checklist! 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. All changesets should bepatch
until SvelteKit 1.0