-
-
Notifications
You must be signed in to change notification settings - Fork 805
Types for route inputs #841
Copy link
Copy link
Closed as not planned
Labels
Description
Describe the feature
Since Nitro generates some types for the response of routes, it would be great if it could also generate types for the input.
As an example:
// routes/index.ts
// This is just a normal eventhandler
export default defineEventHandler(async (event) => {
const { greet } = (await readBody(event)) satisfies Input;
return {
hello: greet,
};
});
// here comes the fun part:
export type Input = {
greet: string;
};Nitro already generates the types for the response from the event handler:
// .nitro/types/nitro.d.ts
interface InternalApi {
'/': Awaited<ReturnType<typeof import('../../routes/index').default>>
}With the types for the input this could look something like this:
interface InternalApi {
'/': Awaited<ReturnType<typeof import('../../routes/index').default>>
}
interface InternalApiInputs {
'/': import("../../routes/index").Input
}Additional information
- Would you be willing to help implement this feature?
Reactions are currently unavailable