Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More TypeScript Fixes #5318

Merged
merged 4 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import useDataProvider from './useDataProvider';
import { useMemo } from 'react';
import { DataProvider, UseDataProviderOptions } from '../types';
import {
DataProvider,
DataProviderProxy,
UseDataProviderOptions,
} from '../types';
import useDeclarativeSideEffects from './useDeclarativeSideEffects';

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

// @ts-ignore
const dataProviderProxy = useMemo(() => {
return new Proxy(dataProvider, {
get: (target, name) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-core/src/export/fetchRelatedRecords.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataProvider, Record, Identifier } from '../types';
import { Record, Identifier, DataProviderProxy } from '../types';

/**
* Helper function for calling the dataProvider.getMany() method,
Expand All @@ -11,7 +11,7 @@ import { DataProvider, Record, Identifier } from '../types';
* post_title: posts[record.post_id].title,
* }));
*/
const fetchRelatedRecords = (dataProvider: DataProvider) => (
const fetchRelatedRecords = (dataProvider: DataProviderProxy) => (
data,
field,
resource
Expand Down
28 changes: 14 additions & 14 deletions packages/ra-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,27 @@ export type LegacyAuthProvider = (
*/

export type DataProvider = {
getList: <RecordType = Record>(
getList: <RecordType extends Record = Record>(
resource: string,
params: GetListParams
) => Promise<GetListResult<RecordType>>;

getOne: <RecordType = Record>(
getOne: <RecordType extends Record = Record>(
resource: string,
params: GetOneParams
) => Promise<GetOneResult<RecordType>>;

getMany: <RecordType = Record>(
getMany: <RecordType extends Record = Record>(
resource: string,
params: GetManyParams
) => Promise<GetManyResult<RecordType>>;

getManyReference: <RecordType = Record>(
getManyReference: <RecordType extends Record = Record>(
resource: string,
params: GetManyReferenceParams
) => Promise<GetManyReferenceResult<RecordType>>;

update: <RecordType = Record>(
update: <RecordType extends Record = Record>(
resource: string,
params: UpdateParams
) => Promise<UpdateResult<RecordType>>;
Expand All @@ -115,12 +115,12 @@ export type DataProvider = {
params: UpdateManyParams
) => Promise<UpdateManyResult>;

create: <RecordType = Record>(
create: <RecordType extends Record = Record>(
resource: string,
params: CreateParams
) => Promise<CreateResult<RecordType>>;

delete: <RecordType = Record>(
delete: <RecordType extends Record = Record>(
resource: string,
params: DeleteParams
) => Promise<DeleteResult<RecordType>>;
Expand Down Expand Up @@ -227,31 +227,31 @@ export type DataProviderResult<RecordType = Record> =
| UpdateManyResult;

export type DataProviderProxy = {
getList: <RecordType = Record>(
getList: <RecordType extends Record = Record>(
resource: string,
params: GetListParams,
options?: UseDataProviderOptions
) => Promise<GetListResult<RecordType>>;

getOne: <RecordType = Record>(
getOne: <RecordType extends Record = Record>(
resource: string,
params: GetOneParams,
options?: UseDataProviderOptions
) => Promise<GetOneResult<RecordType>>;

getMany: <RecordType = Record>(
getMany: <RecordType extends Record = Record>(
resource: string,
params: GetManyParams,
options?: UseDataProviderOptions
) => Promise<GetManyResult<RecordType>>;

getManyReference: <RecordType = Record>(
getManyReference: <RecordType extends Record = Record>(
resource: string,
params: GetManyReferenceParams,
options?: UseDataProviderOptions
) => Promise<GetManyReferenceResult<RecordType>>;

update: <RecordType = Record>(
update: <RecordType extends Record = Record>(
resource: string,
params: UpdateParams,
options?: UseDataProviderOptions
Expand All @@ -263,13 +263,13 @@ export type DataProviderProxy = {
options?: UseDataProviderOptions
) => Promise<UpdateManyResult>;

create: <RecordType = Record>(
create: <RecordType extends Record = Record>(
resource: string,
params: CreateParams,
options?: UseDataProviderOptions
) => Promise<CreateResult<RecordType>>;

delete: <RecordType = Record>(
delete: <RecordType extends Record = Record>(
resource: string,
params: DeleteParams,
options?: UseDataProviderOptions
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/list/ListActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ListActions.defaultProps = {
onUnselectItems: () => null,
};

interface ListActionsProps extends ToolbarProps {
export interface ListActionsProps extends ToolbarProps {
currentSort?: SortPayload;
className?: string;
resource?: string;
Expand Down
17 changes: 13 additions & 4 deletions packages/ra-ui-materialui/src/list/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import BulkActionsToolbar from './BulkActionsToolbar';
import BulkActionsToolbar, {
BulkActionsToolbarProps,
} from './BulkActionsToolbar';
import BulkDeleteAction from './BulkDeleteAction';
import List from './List';
import ListActions from './ListActions';
import ListActions, { ListActionsProps } from './ListActions';
import ListGuesser from './ListGuesser';
import ListToolbar from './ListToolbar';
import ListToolbar, { ListToolbarProps } from './ListToolbar';
import ListView from './ListView';
import Placeholder from './Placeholder';
import SimpleList from './SimpleList';
import SimpleList, { SimpleListProps } from './SimpleList';
import SimpleListLoading from './SimpleListLoading';
import SingleFieldList from './SingleFieldList';

export * from './filter';
export * from './datagrid';
export * from './pagination';

export type {
BulkActionsToolbarProps,
ListActionsProps,
ListToolbarProps,
SimpleListProps,
};

export {
BulkActionsToolbar,
BulkDeleteAction,
Expand Down