Skip to content

Commit bbc2bf3

Browse files
committed
feat(types): add InertiaPage type helper
1 parent 3024d46 commit bbc2bf3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

adonis-typings/inertia.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ declare module '@ioc:EidelLev/Inertia' {
22
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
33
import { ResponseContract } from '@ioc:Adonis/Core/Response';
44

5+
type AdonisControllerMethod = (...args: any) => any;
56
export type ResponseProps = Record<string, unknown>;
6-
export type RenderResponse = Promise<Record<string, unknown> | string | ResponseContract>;
7+
export type RenderResponse<T extends ResponseProps> = Promise<T | string | ResponseContract>;
8+
export type InertiaPage<T extends AdonisControllerMethod> = Exclude<Awaited<ReturnType<T>>, string | ResponseContract>;
79

810
/**
911
* Shared data types
@@ -31,7 +33,7 @@ declare module '@ioc:EidelLev/Inertia' {
3133
* @param {string} component Page component
3234
* @param {ResponseProps} responseProps Props
3335
*/
34-
render(component: string, responseProps?: ResponseProps, pageOnlyProps?: ResponseProps): RenderResponse;
36+
render<T extends ResponseProps>(component: string, responseProps?: T, pageOnlyProps?: ResponseProps): RenderResponse<T>;
3537

3638
/**
3739
* Redirect back with the correct HTTP status code

0 commit comments

Comments
 (0)