-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Generated types #4120
Generated types #4120
Conversation
🦋 Changeset detectedLatest commit: 91e1a66 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 |
This is ready for review but lint is failing because Lines 13 to 27 in eb7492f
update: think i just needed to update pnpm-workspace.yaml |
This reverts commit 536634c.
Would it be fair to understand these changes as striving towards the direction of something like tRPC where you have the client being able to use types auto-generated from server endpoints? |
My tsconfig currently has this in it: Looking at the changes though, it appears I'm doing something wrong. How do I use the svelte-kit version? |
@pheuter It seems like it, to me at least, given that #647 is included in the 1.0 milestone. Although, that may just be wishful thinking on my part. I recently added tRPC to my sveltekit app, in what I can only describe as the cherry to the delicious cake that is sveltekit. The effortless type safety has made what was already a ridiculously fun dev experience even better. Needless to say, I'd be pretty excited if sveltekit were to move in that direction. And I mention tRPC in particular because of how simple or lightweight their approach is, which I feel aligns with svelte's own. In contrast, my original approach of implementing "end-to-end" typesafety was through graphQL. And while it could lead to the same result, the bloat accompanying graphQL quickly gets out of hand where you start questioning whether you're actually improving the dx at all. It ends up sticking out like a sore thumb alongside the simplicity of your typical sveltekit app. P.S. I'm not an expert on the matter by any means, do take what I say with a grain of salt. |
Is this intended to work the same for .ts files in addition to .js with jsdoc comments? I am able to import the generated Minimal example: https://github.com/BrettBedarf/generated-types-minimal
I think the issue is typescript trying to resolve the same file name does not "merge" the import If I manually change the generated .d.ts file to |
@BrettBedarf I'm seeing a similar issue. Eslint is reporting that the file is importing itself. It seems that an endpoints with a In the meantime, try the following workaround. Basically just add a - import type { RequestHandler } from './[slug].json';
+ import type { RequestHandler } from './[slug].json.d'; |
@ambiguous48 good workaround thanks! |
It doesn't seem so—seems like a really strange oversight. But you can hack it to work in TypeScript like this (at least for pages): import type { Load } from "./filename"
export async function load({ params }: Parameters<Load>[0]): Promise<ReturnType<Load>>
{ /* ... */ } If the generated types file exported |
Importing the import type { RequestHandler } from '.svelte-kit/types/src/routes/[slug]';
export const get: RequestHandler = async ({ params }) => {
const { slug } = params; I'm assuming that the |
Former-commit-id: 3d80d6c
This code is a bit ratty, but I figured I'd push it up anyway. It generates
.d.ts
files for every page/endpoint file insrc/routes
(but tucked away in.svelte-kit
via the magic ofrootDirs
). Easier to show than tell:An eventual follow-up would be to automatically type
Props
(and the return value of a shadow endpoint, if noload
function is given) based on a component's<script>
tag.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