Skip to content

Types for route inputs #841

@Blechlawine

Description

@Blechlawine

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions