Dumb dataProvider doesn't type check
See original GitHub issueWhat you were expecting: Bootstrap a dummy application with create-react-app with typescript, and implement a dummy dataProvider. It should compile just fine.
What happened instead: Big Typescript error :
Type '{ getList: (resource: string, params: any) => Promise<{ data: { id: number; toto: string; }[]; total: number; }>; getOne: (resource: string, params: any) => Promise<{ data: { id: number; toto: string; }; }>; ... 6 more ...; deleteMany: (resource: string, params: any) => Promise<...>; }' is not assignable to type 'DataProvider | LegacyDataProvider'.
Type '{ getList: (resource: string, params: any) => Promise<{ data: { id: number; toto: string; }[]; total: number; }>; getOne: (resource: string, params: any) => Promise<{ data: { id: number; toto: string; }; }>; ... 6 more ...; deleteMany: (resource: string, params: any) => Promise<...>; }' is not assignable to type 'DataProvider'.
The types returned by 'getList(...)' are incompatible between these types.
Type 'Promise<{ data: { id: number; toto: string; }[]; total: number; }>' is not assignable to type 'Promise<GetListResult<RecordType>>'.
Type '{ data: { id: number; toto: string; }[]; total: number; }' is not assignable to type 'GetListResult<RecordType>'.
Types of property 'data' are incompatible.
Type '{ id: number; toto: string; }[]' is not assignable to type 'RecordType[]'.
Type '{ id: number; toto: string; }' is not assignable to type 'RecordType'.
'{ id: number; toto: string; }' is assignable to the constraint of type 'RecordType', but 'RecordType' could be instantiated with a different subtype of constraint 'Record'. TS2322
65 | const App: React.FC = () => {
66 | return (
> 67 | <Admin loginPage={LoginPage} dataProvider={dataProvider}/>
| ^
68 | );
69 | };
70 |
Steps to reproduce:
npx create-react-app my-app --template typescript
cd my_app
npm install react-admin
npm start
Related code:
In App.tsx
:
import React from 'react';
import {Admin} from "react-admin";
const dataProvider = {
getList: (resource: string, params: any) => Promise.resolve({data: [{id: 1, toto: "tata"},{id: 2, toto: "tata"}], total: 0}),
getOne: (resource: string, params: any) => Promise.resolve({data: {id: 1, toto: "tata"}}),
getMany: (resource: string, params: any) => Promise.resolve({data: [{id: 1, toto: "tata"}]}),
getManyReference: (resource: string, params: any) => Promise.resolve({data: [{id: 1, toto: "tata"}]}),
create: (resource: string, params: any) => Promise.resolve({data: {id: 1, toto: "tata"}}),
update: (resource: string, params: any) => Promise.resolve({data: {id: 1, toto: "tata"}}),
updateMany: (resource: string, params: any) => Promise.resolve({data: [1]}),
delete: (resource: string, params: any) => Promise.resolve({data: {id: 1, toto: "tata"}}),
deleteMany: (resource: string, params: any) => Promise.resolve({data: [1]}),
};
function App() {
return (
<Admin dataProvider={dataProvider}/>
);
}
export default App;
Other information:
Environment
- React-admin version: 3.9.6
- Last version that did not exhibit the issue (if applicable):
- React version: ^17.0.1
- Browser: Chrome
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:12 (6 by maintainers)
Top Results From Across the Web
PHPUnit Data Provider Argument Count Error - Stack Overflow
:-( I test your code and seems work fine. Check the error is i some other place. Same thing is happening for all...
Read more >Unit Testing Tutorial Part II: Assertions, Writing a Useful Test ...
### @dataProvider A test method can accept arbitrary arguments. These arguments are to be provided by a data provider method.
Read more >Verification of AWS Data Provider for SAP in SAP system ...
The AWS Data Provider for SAP exposes AWS-specific metrics through an XML page at ... Type dump ccm and press Enter to list...
Read more >Excessive SSSD backtrace log messages
After upgrading to RHEL 8.5, SSSD writes excessive backtrace log messages filling storage. Backtrace log messages are recorded in /var/log/sssd/ ...
Read more >Management Reporter Data Mart - DDM Adapter Issue
Object graph for type 'Microsoft.Dynamics.Performance.DataProvider.Core.EntitySettingCollection' contains cycles and cannot be serialized if ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Had the similar issue on
4.0.2
withgetOne
:And my
getOne
:I think the key here is
The types returned by 'getOne(...)' are incompatible
Setting proper return type
GetOneResult
has fixed the issue:@harishy100 This is an open-source project. Anyone can contribute. It’s not a critical problem for the core team, so we dedicate time to other problems for now.
If you want the bug fixed quickly, the best way is to fork the project, fix it yourself, and open a PR to have your fix merged in the react-admin code. If you don’t have the time or skills to do so, consider hiring Marmelab to fix the bug for you.