-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Interfaces for shadow endpoints #5468
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
Comments
It throws an error because you didn't pass your object type through the |
Thanks for the quick response!
It's not quite clear how to use |
Is this corrrect? It works but is a bit clunky in terms of DX. Also not sure what the first slot needs when using a parameterized endpoint like |
I think you can do something like this using SvelteKit's generated types, which will automatically populate that first slot for parameterized endpoints: import type { RequestHandler } from './__types/things';
interface GetOutput { things: Thing[]}
export const get: RequestHandler<GetOutput> = async function ({ request }) { } |
@geoffrich The generated types do not import for me, how do you generate them? I did manage to make it work like @pikeas suggested, complete example: import type { RequestHandler } from '@sveltejs/kit';
interface User {
name: string,
}
interface PostOutput { user?: User | null }
export const POST: RequestHandler<Record<string, string>, PostOutput> = async ({ request }) => { /* OK to return { user: { name: "foo" } } */ } |
Describe the bug
#1997 seems to still be happening - when
get()
is typed as a RequestHandler and returns data defined as an interface, Typescript throws aJSONValue
complaint.Reproduction
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: