-
-
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
RequestEvent and RequestHandlerOutput should be public shapes #4138
Comments
Relatedly, the shape of I couldn't find this in the changelog, but here's the commit. This causes a problem at least in typescript. import type { RequestHandler, RequestHandlerOutput } from '@sveltejs/kit';
/**
* The way one would expect it to work. Error:
* The return type of an async function or method must be the global Promise<T> type.
*/
export const get: RequestHandler = async ({request}): RequestHandlerOutput => {
// do something async here
return {
status: 200
};
}
/**
* For completeness, I tried returning a promise of a maybe promise.
* Error: (verbose, basically, that a Promise is not a RequestHandlerOutput)
* Type '({ request }: RequestEvent<Record<string, string>>) => Promise<RequestHandlerOutput<Body>>'
* is not assignable to type 'RequestHandler<Record<string, string>, Body>'. Blah blah blah...
*/
export const post: RequestHandler = async ({request}): Promise<RequestHandlerOutput> => {
// do something async here
return {
status: 200
}
} The simple way to fix this is to move the |
I'm a bit confused why this is closed now even though it's still an issue, I still get warnings when defining hook functions and request handlers because i cannot define the event parameter by it's actual type, which is consider the following
At least in IntelliJ Idea this yields
Which is correct. So am I not supposed to declare the type of the event parameter? I'd like to. |
Describe the problem
This change moved
RequestEvent
andEndpointOutput
intokit/types/private.d.ts
fromkit/types/index.d.ts
, making them "private" rather than reliable.These two types in particular seem to define the basic contract for endpoints. You get a
RequestEvent
, you return anEndpointOutput
. Unless this contract is going to change radically these types should be made public again.Describe the proposed solution
Make
RequestEvent
andEndpointOutput
public.Alternatives considered
RequestEvent
andEndpointOutput
types, even though they are ostensibly private.RequestHandler<Params = Record<string, string>, Output extends Body = Body>
. A note about this. TheParams
generic is of no use to me in userland (though maybe I don't understand it.) For an endpoint at/foo/[fooId]
it should be a given thatconst { fooId } = event.params
will always work, be a non-empty string, etc. Is this something internal / adapter-specific that leaked out into the public API?Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: