I don't understand why response.data doesn't fit to TData
import { BaseRecord, DataProvider, GetListParams, GetListResponse } from '@refinedev/core';
import axios from 'axios';
class SearchResultItem implements BaseRecord {
constructor(
public id: string,
public title: string,
public date: string,
public highlights: string[],
) {}
}
class Search implements DataProvider {
private httpClient = axios.create({ baseURL: globalThis.SETTINGS.API_URL });
async getList<TData extends BaseRecord = SearchResultItem>(
params: GetListParams,
): Promise<GetListResponse<TData>> {
const response = await this.httpClient.get<SearchResultItem[]>('/items', { params });
return { data: response.data, total: response.data.length }; // response.data has a wrong type
}
}
export default Search;
Error:
Type 'SearchResultItem[]' is not assignable to type 'TData[]'.
Type 'SearchResultItem' is not assignable to type 'TData'.
'SearchResultItem' is assignable to the constraint of type 'TData', but 'TData' could be instantiated with a different subtype of constraint 'BaseRecord'.ts(2322)
What am I doing wrong?
PS neural net suggest weird solution:
return { data: response.data as unknown as TData[], total: response.data.length };