Skip to content

Commit 127797f

Browse files
committed
Move module declaration into definition file, override PageProps and add template macro types
1 parent b1709db commit 127797f

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

resources/js/app.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@ import { createApp, h } from 'vue';
77
import { ZiggyVue } from 'ziggy-js';
88
import { initializeTheme } from './composables/useAppearance';
99

10-
// Extend ImportMeta interface for Vite...
11-
declare module 'vite/client' {
12-
interface ImportMetaEnv {
13-
readonly VITE_APP_NAME: string;
14-
[key: string]: string | boolean | undefined;
15-
}
16-
17-
interface ImportMeta {
18-
readonly env: ImportMetaEnv;
19-
readonly glob: <T>(pattern: string) => Record<string, () => Promise<T>>;
20-
}
21-
}
22-
2310
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
2411

2512
createInertiaApp({

resources/js/types/globals.d.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1-
import type { route as routeFn } from 'ziggy-js';
1+
import { AppPageProps } from '@/types/index';
2+
import { createHeadManager, Page, Router } from '@inertiajs/core';
23

3-
declare global {
4-
const route: typeof routeFn;
4+
// Extend ImportMeta interface for Vite...
5+
declare module 'vite/client' {
6+
interface ImportMetaEnv {
7+
readonly VITE_APP_NAME: string;
8+
9+
[key: string]: string | boolean | undefined;
10+
}
11+
12+
interface ImportMeta {
13+
readonly env: ImportMetaEnv;
14+
readonly glob: <T>(pattern: string) => Record<string, () => Promise<T>>;
15+
}
16+
}
17+
18+
// Declare shared props for Inertia and App pages...
19+
declare module '@inertiajs/core' {
20+
interface PageProps extends InertiaPageProps, AppPageProps {}
21+
}
22+
23+
// Add typings for Inertia's $page and $headManager properties...
24+
declare module '@vue/runtime-core' {
25+
interface ComponentCustomProperties {
26+
$inertia: typeof Router;
27+
$page: Page;
28+
$headManager: ReturnType<typeof createHeadManager>;
29+
route: AppRouter;
30+
}
531
}

0 commit comments

Comments
 (0)