Skip to content

Commit 0a47f8d

Browse files
authored
Merge pull request #5318 from marmelab/typescript
More TypeScript Fixes
2 parents 83252f3 + ff0d5d1 commit 0a47f8d

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

packages/ra-core/src/dataProvider/useDataProviderWithDeclarativeSideEffects.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import useDataProvider from './useDataProvider';
22
import { useMemo } from 'react';
3-
import { DataProvider, UseDataProviderOptions } from '../types';
3+
import {
4+
DataProvider,
5+
DataProviderProxy,
6+
UseDataProviderOptions,
7+
} from '../types';
48
import useDeclarativeSideEffects from './useDeclarativeSideEffects';
59

610
/**
@@ -9,10 +13,11 @@ import useDeclarativeSideEffects from './useDeclarativeSideEffects';
913
*
1014
* @deprecated This is for backward compatibility only and will be removed in next major version.
1115
*/
12-
const useDataProviderWithDeclarativeSideEffects = (): DataProvider => {
16+
const useDataProviderWithDeclarativeSideEffects = (): DataProviderProxy => {
1317
const dataProvider = useDataProvider();
1418
const getSideEffects = useDeclarativeSideEffects();
1519

20+
// @ts-ignore
1621
const dataProviderProxy = useMemo(() => {
1722
return new Proxy(dataProvider, {
1823
get: (target, name) => {

packages/ra-core/src/export/fetchRelatedRecords.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DataProvider, Record, Identifier } from '../types';
1+
import { Record, Identifier, DataProviderProxy } from '../types';
22

33
/**
44
* Helper function for calling the dataProvider.getMany() method,
@@ -11,7 +11,7 @@ import { DataProvider, Record, Identifier } from '../types';
1111
* post_title: posts[record.post_id].title,
1212
* }));
1313
*/
14-
const fetchRelatedRecords = (dataProvider: DataProvider) => (
14+
const fetchRelatedRecords = (dataProvider: DataProviderProxy) => (
1515
data,
1616
field,
1717
resource

packages/ra-core/src/types.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,27 @@ export type LegacyAuthProvider = (
8585
*/
8686

8787
export type DataProvider = {
88-
getList: <RecordType = Record>(
88+
getList: <RecordType extends Record = Record>(
8989
resource: string,
9090
params: GetListParams
9191
) => Promise<GetListResult<RecordType>>;
9292

93-
getOne: <RecordType = Record>(
93+
getOne: <RecordType extends Record = Record>(
9494
resource: string,
9595
params: GetOneParams
9696
) => Promise<GetOneResult<RecordType>>;
9797

98-
getMany: <RecordType = Record>(
98+
getMany: <RecordType extends Record = Record>(
9999
resource: string,
100100
params: GetManyParams
101101
) => Promise<GetManyResult<RecordType>>;
102102

103-
getManyReference: <RecordType = Record>(
103+
getManyReference: <RecordType extends Record = Record>(
104104
resource: string,
105105
params: GetManyReferenceParams
106106
) => Promise<GetManyReferenceResult<RecordType>>;
107107

108-
update: <RecordType = Record>(
108+
update: <RecordType extends Record = Record>(
109109
resource: string,
110110
params: UpdateParams
111111
) => Promise<UpdateResult<RecordType>>;
@@ -115,12 +115,12 @@ export type DataProvider = {
115115
params: UpdateManyParams
116116
) => Promise<UpdateManyResult>;
117117

118-
create: <RecordType = Record>(
118+
create: <RecordType extends Record = Record>(
119119
resource: string,
120120
params: CreateParams
121121
) => Promise<CreateResult<RecordType>>;
122122

123-
delete: <RecordType = Record>(
123+
delete: <RecordType extends Record = Record>(
124124
resource: string,
125125
params: DeleteParams
126126
) => Promise<DeleteResult<RecordType>>;
@@ -227,31 +227,31 @@ export type DataProviderResult<RecordType = Record> =
227227
| UpdateManyResult;
228228

229229
export type DataProviderProxy = {
230-
getList: <RecordType = Record>(
230+
getList: <RecordType extends Record = Record>(
231231
resource: string,
232232
params: GetListParams,
233233
options?: UseDataProviderOptions
234234
) => Promise<GetListResult<RecordType>>;
235235

236-
getOne: <RecordType = Record>(
236+
getOne: <RecordType extends Record = Record>(
237237
resource: string,
238238
params: GetOneParams,
239239
options?: UseDataProviderOptions
240240
) => Promise<GetOneResult<RecordType>>;
241241

242-
getMany: <RecordType = Record>(
242+
getMany: <RecordType extends Record = Record>(
243243
resource: string,
244244
params: GetManyParams,
245245
options?: UseDataProviderOptions
246246
) => Promise<GetManyResult<RecordType>>;
247247

248-
getManyReference: <RecordType = Record>(
248+
getManyReference: <RecordType extends Record = Record>(
249249
resource: string,
250250
params: GetManyReferenceParams,
251251
options?: UseDataProviderOptions
252252
) => Promise<GetManyReferenceResult<RecordType>>;
253253

254-
update: <RecordType = Record>(
254+
update: <RecordType extends Record = Record>(
255255
resource: string,
256256
params: UpdateParams,
257257
options?: UseDataProviderOptions
@@ -263,13 +263,13 @@ export type DataProviderProxy = {
263263
options?: UseDataProviderOptions
264264
) => Promise<UpdateManyResult>;
265265

266-
create: <RecordType = Record>(
266+
create: <RecordType extends Record = Record>(
267267
resource: string,
268268
params: CreateParams,
269269
options?: UseDataProviderOptions
270270
) => Promise<CreateResult<RecordType>>;
271271

272-
delete: <RecordType = Record>(
272+
delete: <RecordType extends Record = Record>(
273273
resource: string,
274274
params: DeleteParams,
275275
options?: UseDataProviderOptions

packages/ra-ui-materialui/src/list/ListActions.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ListActions.defaultProps = {
7373
onUnselectItems: () => null,
7474
};
7575

76-
interface ListActionsProps extends ToolbarProps {
76+
export interface ListActionsProps extends ToolbarProps {
7777
currentSort?: SortPayload;
7878
className?: string;
7979
resource?: string;

packages/ra-ui-materialui/src/list/index.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
import BulkActionsToolbar from './BulkActionsToolbar';
1+
import BulkActionsToolbar, {
2+
BulkActionsToolbarProps,
3+
} from './BulkActionsToolbar';
24
import BulkDeleteAction from './BulkDeleteAction';
35
import List from './List';
4-
import ListActions from './ListActions';
6+
import ListActions, { ListActionsProps } from './ListActions';
57
import ListGuesser from './ListGuesser';
6-
import ListToolbar from './ListToolbar';
8+
import ListToolbar, { ListToolbarProps } from './ListToolbar';
79
import ListView from './ListView';
810
import Placeholder from './Placeholder';
9-
import SimpleList from './SimpleList';
11+
import SimpleList, { SimpleListProps } from './SimpleList';
1012
import SimpleListLoading from './SimpleListLoading';
1113
import SingleFieldList from './SingleFieldList';
1214

1315
export * from './filter';
1416
export * from './datagrid';
1517
export * from './pagination';
1618

19+
export type {
20+
BulkActionsToolbarProps,
21+
ListActionsProps,
22+
ListToolbarProps,
23+
SimpleListProps,
24+
};
25+
1726
export {
1827
BulkActionsToolbar,
1928
BulkDeleteAction,

0 commit comments

Comments
 (0)