reactjstypescriptlaravelinertiajs

Property auth is missing but required in pageProps (Inertia)


I am working with Inertia and laravel. But I am stuck at this point. I am not sure why this error is coming. If anyone knows the solution to this. Please help me get rid of this error.

enter image description here

export interface Invoice {
    id: number;
    invoiceName: string;
    invoiceNumber: string;
    fromName: string;
    fromEmail: string;
    fromAddress: string;
    clientName: string;
    clientEmail: string;
    clientAddress: string;
    invoiceItemDescription: string;
    note?: string;
    dueDate: string; // e.g., "Net 30" or a date string
    currency: "USD" | "EUR";
    date: string; // Date string in ISO format
    rate: number;
    quantity: number;
    total: number;
}

export type InvoiceProps<T extends Record<string, unknown> = Record<string, unknown>> = T & {
    invoices: Invoice[]
};

Any solution is appreciated!


Solution

  • The problem is that your InvoiceProps isn’t extending PageProps, and it SHOULD, which includes things like auth. For example, PageProps usually has an auth property, and if you don’t extend it, you’ll miss that.

    Here’s the fix:

    import { PageProps } from '@inertiajs/core';
    
    export type InvoiceProps<T extends Record<string, unknown> = Record<string, unknown>> = PageProps & {
        invoices: Invoice[];
    };
    

    Now, InvoiceProps will include everything in PageProps (like auth) along with your invoices.