Skip to content
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

Types for route inputs #841

Open
1 task done
Blechlawine opened this issue Jan 14, 2023 · 0 comments
Open
1 task done

Types for route inputs #841

Blechlawine opened this issue Jan 14, 2023 · 0 comments
Labels
enhancement New feature or request types

Comments

@Blechlawine
Copy link

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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants