Skip to content

Commit 549ef65

Browse files
committed
types: Refactor global types and add Paginator interfaces for improved type safety
1 parent 25c7787 commit 549ef65

File tree

3 files changed

+62
-34
lines changed

3 files changed

+62
-34
lines changed

resources/js/types/global.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import type { route as routeFn } from 'ziggy-js';
22

33
declare global {
4-
const route: typeof routeFn;
4+
const route: typeof routeFn;
5+
6+
// Props for pages that use Inertia
7+
type PageProps<T = unknown> = App.Data.InertiaRequestData & T;
8+
9+
// Props for authenticated pages
10+
type AuthenticatedPageProps<T = unknown> = App.Data.InertiaRequestData &
11+
T & {
12+
user: App.Data.UserData;
13+
};
514
}

resources/js/types/index.d.ts

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,18 @@
11
import { LucideIcon } from 'lucide-react';
2-
import type { Config } from 'ziggy-js';
3-
4-
export interface Auth {
5-
user: User;
6-
}
72

83
export interface BreadcrumbItem {
9-
title: string;
10-
href: string;
4+
title: string;
5+
href: string;
116
}
127

138
export interface NavGroup {
14-
title: string;
15-
items: NavItem[];
9+
title: string;
10+
items: NavItem[];
1611
}
1712

1813
export interface NavItem {
19-
title: string;
20-
href: string;
21-
icon?: LucideIcon | null;
22-
isActive?: boolean;
23-
}
24-
25-
export interface SharedData {
26-
name: string;
27-
quote: { message: string; author: string };
28-
auth: Auth;
29-
ziggy: Config & { location: string };
30-
sidebarOpen: boolean;
31-
[key: string]: unknown;
32-
}
33-
34-
export interface User {
35-
id: number;
36-
name: string;
37-
email: string;
38-
avatar?: string;
39-
email_verified_at: string | null;
40-
created_at: string;
41-
updated_at: string;
42-
[key: string]: unknown; // This allows for additional properties...
14+
title: string;
15+
href: string;
16+
icon?: LucideIcon | null;
17+
isActive?: boolean;
4318
}

resources/js/types/laravel.d.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace App {
2+
/**
3+
* Represents a link in a paginator.
4+
* Each link has a URL, label, and an active state.
5+
*/
6+
export interface PaginatorLink {
7+
url: string | null;
8+
label: string;
9+
active: boolean;
10+
}
11+
12+
/**
13+
* Represents a paginated response.
14+
* It contains the current page, data items, and pagination links.
15+
*/
16+
export interface Paginator<T = unknown> {
17+
current_page: number;
18+
data: T[];
19+
first_page_url: string;
20+
from: number | null;
21+
last_page: number;
22+
last_page_url: string;
23+
links: PaginatorLink[];
24+
next_page_url: string | null;
25+
path: string;
26+
per_page: number;
27+
prev_page_url: string | null;
28+
to: number | null;
29+
total: number;
30+
}
31+
32+
/**
33+
* @see https://vscode.dev/github/SamuelBisberg/react-starter-kit/blob/main/app/Traits/EnumTrait.php#L12
34+
*
35+
* Represents a collection of enum values with additional properties.
36+
* Each item in the collection has a `value`, `label`, `description`, and `color`.
37+
*/
38+
export type EnumCollection = Array<{
39+
value: string;
40+
label: string;
41+
description?: string;
42+
color?: string;
43+
}>;
44+
}

0 commit comments

Comments
 (0)