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

[TypeScript] Fix regression in type of <FunctionField> render #8964

Merged
merged 1 commit into from
Jun 1, 2023
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
40 changes: 40 additions & 0 deletions packages/ra-ui-materialui/src/field/FunctionField.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from 'react';

import { RecordContextProvider } from 'ra-core';
import { FunctionField } from './FunctionField';

export default { title: 'ra-ui-materialui/fields/FunctionField' };

export const Basic = () => (
<RecordContextProvider value={{ firstName: 'John', lastName: 'Doe' }}>
<FunctionField
render={record => `${record.firstName} ${record.lastName}`}
/>
</RecordContextProvider>
);

type User = {
id: number;
firstName: string;
lastName: string;
};

export const Typed = () => (
<RecordContextProvider<User>
value={{ id: 123, firstName: 'John', lastName: 'Doe' }}
>
<FunctionField<User>
render={record => `${record?.firstName} ${record?.lastName}`}
/>
</RecordContextProvider>
);

export const NonRegression = () => (
<RecordContextProvider value={{ firstName: 'John', lastName: 'Doe' }}>
<FunctionField
render={(record?: User) =>
`${record?.firstName} ${record?.lastName}`
}
/>
</RecordContextProvider>
);
6 changes: 2 additions & 4 deletions packages/ra-ui-materialui/src/field/FunctionField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import { FieldProps, fieldPropTypes } from './types';
* />
*/

export const FunctionField = <
RecordType extends Record<string, unknown> = Record<string, any>
>(
export const FunctionField = <RecordType extends Record<string, unknown> = any>(
props: FunctionFieldProps<RecordType>
) => {
const { className, source = '', render, ...rest } = props;
Expand Down Expand Up @@ -49,7 +47,7 @@ FunctionField.propTypes = {
};

export interface FunctionFieldProps<
RecordType extends Record<string, unknown> = Record<string, any>
RecordType extends Record<string, unknown> = any
> extends FieldProps<RecordType>,
Omit<TypographyProps, 'textAlign'> {
render: (record?: RecordType, source?: string) => any;
Expand Down