I have a problem in typescript declaration in next js . When I ran project , its working well . But when i run build , its showing follwoing error .
Error showing when i run build next js app
Property 'reports' is incompatible with index signature.
Type '{ data: ReportType[]; meta: MetaDataType; }' is not assignable to type 'never'.
26 |
27 | // Check the prop type of the entry function
> 28 | checkFields<Diff<PageProps, FirstArg<TEntry['default']>, 'default'>>()
| ^
29 |
30 | // Check the arguments and return type of the generateMetadata function
31 | if ('generateMetadata' in entry) {
This is parent component that using Report Table
const ReportsPage = () => {
const [generalSearch, setGeneralSearch] = useState<string>("");
const [amount, setAmount] = useState<number>(0);
const [confirmStatus, setConfirmStatus] = useState<number>();
const [type, setType] = useState<string>("");
const [page, setPage] = useState<number>(1);
const [createdAt, setCreatedAt] = useState<string>("");
const t = useTranslations("Translation");
const { currentLocale } = useLocale();
const { data: reports, isLoading: loading } = FetchReportsService(
generalSearch,
amount,
confirmStatus,
type,
createdAt,
page
);
<ReportTable
reports={reports}
loading={loading}
onPageChange={handlePageChange}
/>
Fetch Report Service file is as like this and in this file I am using tanstack query
export const FetchReportsService = (
generalSearch?:string,
amount?:number,
confirmStatus?:number,
type?:string,
createdAt?:string,
page?:number
) => {
return useFetchQuery<ReportsResponse>(
["reports", generalSearch, amount, confirmStatus, type, createdAt, page],
() =>
fetchReportsApi(
generalSearch,
amount,
confirmStatus,
type,
createdAt,
page
)
);
};
type for ReportsResponse
import { MetaDataType } from "../Share/MetaDataType";
export interface ReportType {
id: number;
amount: number;
description: string;
type: 'EXPENSE' | 'INCOME'; // Adjust according to possible types
confirmStatus: number;
reporter: User;
verifier: User;
createdAt: Date;
updatedAt: Date;
}
interface User{
id:number,
name:string,
}
export interface ReportsResponse{
data:ReportType[],
meta:MetaDataType
}
I delcared typescript as like this
type ReportTableProps = {
reports: {
data: ReportType[];
meta: MetaDataType
};
loading: boolean;
onPageChange: (page: number) => void;
}
const ReportTable = ({ reports, loading, onPageChange }: ReportTableProps) => {
Meta Data Type is export from another file as like this
export interface MetaDataType {
currentPage: number;
endOffset: number;
startOffset: number;
totalItems: number;
totalPages: number;
}
This is the api that send from backend
{
"data": [
{
"id": 1,
"amount": 4000,
"description": "asasa1",
"type": "EXPENSE",
"confirmStatus": 1,
"reporter": {
"id": 2,
"name": "ADMIN"
},
"verifier": {
"id": 2,
"name": "ADMIN"
},
"createdAt": "2024-06-Aug 09:59 AM",
"updatedAt": "2024-13-Aug 11:40 AM"
}
],
"meta": {
"currentPage": 1,
"totalPages": 1,
"startOffset": 1,
"endOffset": 1,
"totalItems": 1
}
}
Please Kindly check how can i fix this error ?