From ae1bda64a3f5496ed37c15f82bd7f8649b9f7bda Mon Sep 17 00:00:00 2001 From: Balazs Barabas Date: Fri, 20 Dec 2024 16:35:05 +0200 Subject: [PATCH 1/2] removed interface declaration and added the updated type declaration to the config.stub --- src/types.ts | 11 +---------- stubs/config.stub | 2 +- tests/configure.spec.ts | 6 +++--- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/types.ts b/src/types.ts index ff1da11..54c410e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -184,12 +184,6 @@ export type InferSharedProps> = Returns Awaited>['sharedData'] > -/** - * The shared props inferred from the user config user-land. - * Should be module augmented by the user - */ -export interface SharedProps {} - /** * Helper for infering the page props from a Controller method that returns * inertia.render @@ -214,10 +208,7 @@ export type InferPageProps< Method extends keyof Controller, > = Controller[Method] extends (...args: any[]) => any ? Simplify< - Serialize< - InferProps>, PageObject>['props']> & - SharedProps - > + Serialize>, PageObject>['props']>> > : never diff --git a/stubs/config.stub b/stubs/config.stub index a8d5856..faf16e3 100644 --- a/stubs/config.stub +++ b/stubs/config.stub @@ -29,5 +29,5 @@ const inertiaConfig = defineConfig({ export default inertiaConfig declare module '@adonisjs/inertia/types' { - export interface SharedProps extends InferSharedProps {} + export type SharedProps = InferSharedProps & {} } diff --git a/tests/configure.spec.ts b/tests/configure.spec.ts index 26c44cb..da34814 100644 --- a/tests/configure.spec.ts +++ b/tests/configure.spec.ts @@ -261,7 +261,7 @@ test.group('Frameworks | SSR', (group) => { export default inertiaConfig declare module '@adonisjs/inertia/types' { - export interface SharedProps extends InferSharedProps {} + export type SharedProps = InferSharedProps & {} }" `) }) @@ -314,7 +314,7 @@ test.group('Frameworks | SSR', (group) => { export default inertiaConfig declare module '@adonisjs/inertia/types' { - export interface SharedProps extends InferSharedProps {} + export type SharedProps = InferSharedProps & {} }" `) }) @@ -367,7 +367,7 @@ test.group('Frameworks | SSR', (group) => { export default inertiaConfig declare module '@adonisjs/inertia/types' { - export interface SharedProps extends InferSharedProps {} + export type SharedProps = InferSharedProps & {} }" `) }) From c93cdaa349a961e573841aceba152d1f30c48d1c Mon Sep 17 00:00:00 2001 From: Balazs Barabas Date: Mon, 23 Dec 2024 17:51:55 +0200 Subject: [PATCH 2/2] updated interface declaration in config with PageProps --- src/types.ts | 11 ++++++++++- stubs/config.stub | 4 ++-- tests/configure.spec.ts | 12 ++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/types.ts b/src/types.ts index 54c410e..ff1da11 100644 --- a/src/types.ts +++ b/src/types.ts @@ -184,6 +184,12 @@ export type InferSharedProps> = Returns Awaited>['sharedData'] > +/** + * The shared props inferred from the user config user-land. + * Should be module augmented by the user + */ +export interface SharedProps {} + /** * Helper for infering the page props from a Controller method that returns * inertia.render @@ -208,7 +214,10 @@ export type InferPageProps< Method extends keyof Controller, > = Controller[Method] extends (...args: any[]) => any ? Simplify< - Serialize>, PageObject>['props']>> + Serialize< + InferProps>, PageObject>['props']> & + SharedProps + > > : never diff --git a/stubs/config.stub b/stubs/config.stub index faf16e3..d71ebc3 100644 --- a/stubs/config.stub +++ b/stubs/config.stub @@ -2,7 +2,7 @@ exports({ to: app.configPath('inertia.ts') }) }}} import { defineConfig } from '@adonisjs/inertia' -import type { InferSharedProps } from '@adonisjs/inertia/types' +import type { InferSharedProps, PageProps } from '@adonisjs/inertia/types' const inertiaConfig = defineConfig({ /** @@ -29,5 +29,5 @@ const inertiaConfig = defineConfig({ export default inertiaConfig declare module '@adonisjs/inertia/types' { - export type SharedProps = InferSharedProps & {} + export interface SharedProps extends InferSharedProps, PageProps {} } diff --git a/tests/configure.spec.ts b/tests/configure.spec.ts index da34814..49498bb 100644 --- a/tests/configure.spec.ts +++ b/tests/configure.spec.ts @@ -234,7 +234,7 @@ test.group('Frameworks | SSR', (group) => { const inertiaConfig = await fs.contents('config/inertia.ts') assert.snapshot(inertiaConfig).matchInline(` "import { defineConfig } from '@adonisjs/inertia' - import type { InferSharedProps } from '@adonisjs/inertia/types' + import type { InferSharedProps, PageProps } from '@adonisjs/inertia/types' const inertiaConfig = defineConfig({ /** @@ -261,7 +261,7 @@ test.group('Frameworks | SSR', (group) => { export default inertiaConfig declare module '@adonisjs/inertia/types' { - export type SharedProps = InferSharedProps & {} + export interface SharedProps extends InferSharedProps, PageProps {} }" `) }) @@ -287,7 +287,7 @@ test.group('Frameworks | SSR', (group) => { assert.snapshot(inertiaConfig).matchInline(` "import { defineConfig } from '@adonisjs/inertia' - import type { InferSharedProps } from '@adonisjs/inertia/types' + import type { InferSharedProps, PageProps } from '@adonisjs/inertia/types' const inertiaConfig = defineConfig({ /** @@ -314,7 +314,7 @@ test.group('Frameworks | SSR', (group) => { export default inertiaConfig declare module '@adonisjs/inertia/types' { - export type SharedProps = InferSharedProps & {} + export interface SharedProps extends InferSharedProps, PageProps {} }" `) }) @@ -340,7 +340,7 @@ test.group('Frameworks | SSR', (group) => { const inertiaConfig = await fs.contents('config/inertia.ts') assert.snapshot(inertiaConfig).matchInline(` "import { defineConfig } from '@adonisjs/inertia' - import type { InferSharedProps } from '@adonisjs/inertia/types' + import type { InferSharedProps, PageProps } from '@adonisjs/inertia/types' const inertiaConfig = defineConfig({ /** @@ -367,7 +367,7 @@ test.group('Frameworks | SSR', (group) => { export default inertiaConfig declare module '@adonisjs/inertia/types' { - export type SharedProps = InferSharedProps & {} + export interface SharedProps extends InferSharedProps, PageProps {} }" `) })