@hemilrajput/laravel-typegen-helpers
v2.0.0
Published
TypeScript utility types for Laravel TypeGen — PaginatedResponse, InertiaForm, ApiResource, and more.
Maintainers
Readme
@hemilrajput/laravel-typegen-helpers
TypeScript utility types for the Laravel TypeGen ecosystem.
Install
npm install @hemilrajput/laravel-typegen-helpers
# or
pnpm add @hemilrajput/laravel-typegen-helpersUtilities
PaginatedResponse<T>
Mirrors Model::paginate() JSON shape.
import type { PaginatedResponse } from '@hemilrajput/laravel-typegen-helpers';
const res: PaginatedResponse<User> = await fetch('/api/users').then(r => r.json());
console.log(res.meta.total);InertiaForm<T>
Typed wrapper for Inertia's useForm().
import type { InertiaForm } from '@hemilrajput/laravel-typegen-helpers';
import { useForm } from '@inertiajs/vue3';
const form: InertiaForm<{ name: string; email: string }> = useForm({ name: '', email: '' });ApiResource<T> / ApiResourceCollection<T>
Envelope types for Laravel JsonResource responses.
import type { ApiResource } from '@hemilrajput/laravel-typegen-helpers';
const res: ApiResource<User> = await fetch('/api/users/1').then(r => r.json());Relation<T>
Mirrors the Relation<T> helper emitted by laravel-typegen when relations.wrap_with_relation is enabled.
import type { Relation } from '@hemilrajput/laravel-typegen-helpers';
interface User {
id: number;
posts: Relation<Post>;
}Utility Types
| Type | Description |
|---|---|
| DeepPartial<T> | Recursively makes all fields optional |
| RequireFields<T, K> | Makes specific keys required |
| Unarray<T> | Extracts element type from array |
| EnumRecord<K, V> | Record keyed by enum/union string |
License
MIT
