Skip to content

Commit bf84341

Browse files
authored
Merge pull request #8964 from marmelab/FunctionField-TS-regression
[TypeScript] Fix regression in type of `<FunctionField>` `render`
2 parents ee60917 + 8ba0f6f commit bf84341

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from 'react';
2+
3+
import { RecordContextProvider } from 'ra-core';
4+
import { FunctionField } from './FunctionField';
5+
6+
export default { title: 'ra-ui-materialui/fields/FunctionField' };
7+
8+
export const Basic = () => (
9+
<RecordContextProvider value={{ firstName: 'John', lastName: 'Doe' }}>
10+
<FunctionField
11+
render={record => `${record.firstName} ${record.lastName}`}
12+
/>
13+
</RecordContextProvider>
14+
);
15+
16+
type User = {
17+
id: number;
18+
firstName: string;
19+
lastName: string;
20+
};
21+
22+
export const Typed = () => (
23+
<RecordContextProvider<User>
24+
value={{ id: 123, firstName: 'John', lastName: 'Doe' }}
25+
>
26+
<FunctionField<User>
27+
render={record => `${record?.firstName} ${record?.lastName}`}
28+
/>
29+
</RecordContextProvider>
30+
);
31+
32+
export const NonRegression = () => (
33+
<RecordContextProvider value={{ firstName: 'John', lastName: 'Doe' }}>
34+
<FunctionField
35+
render={(record?: User) =>
36+
`${record?.firstName} ${record?.lastName}`
37+
}
38+
/>
39+
</RecordContextProvider>
40+
);

packages/ra-ui-materialui/src/field/FunctionField.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import { FieldProps, fieldPropTypes } from './types';
1818
* />
1919
*/
2020

21-
export const FunctionField = <
22-
RecordType extends Record<string, unknown> = Record<string, any>
23-
>(
21+
export const FunctionField = <RecordType extends Record<string, unknown> = any>(
2422
props: FunctionFieldProps<RecordType>
2523
) => {
2624
const { className, source = '', render, ...rest } = props;
@@ -49,7 +47,7 @@ FunctionField.propTypes = {
4947
};
5048

5149
export interface FunctionFieldProps<
52-
RecordType extends Record<string, unknown> = Record<string, any>
50+
RecordType extends Record<string, unknown> = any
5351
> extends FieldProps<RecordType>,
5452
Omit<TypographyProps, 'textAlign'> {
5553
render: (record?: RecordType, source?: string) => any;

0 commit comments

Comments
 (0)