From 8ba0f6f6c52a9152867e497dd593954abc25a07e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Kaiser Date: Thu, 1 Jun 2023 11:54:05 +0200 Subject: [PATCH] [TypeScript] Fix regression in type of `` `render` --- .../src/field/FunctionField.stories.tsx | 40 +++++++++++++++++++ .../src/field/FunctionField.tsx | 6 +-- 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 packages/ra-ui-materialui/src/field/FunctionField.stories.tsx diff --git a/packages/ra-ui-materialui/src/field/FunctionField.stories.tsx b/packages/ra-ui-materialui/src/field/FunctionField.stories.tsx new file mode 100644 index 00000000000..fc651f9e8b2 --- /dev/null +++ b/packages/ra-ui-materialui/src/field/FunctionField.stories.tsx @@ -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 = () => ( + + `${record.firstName} ${record.lastName}`} + /> + +); + +type User = { + id: number; + firstName: string; + lastName: string; +}; + +export const Typed = () => ( + + value={{ id: 123, firstName: 'John', lastName: 'Doe' }} + > + + render={record => `${record?.firstName} ${record?.lastName}`} + /> + +); + +export const NonRegression = () => ( + + + `${record?.firstName} ${record?.lastName}` + } + /> + +); diff --git a/packages/ra-ui-materialui/src/field/FunctionField.tsx b/packages/ra-ui-materialui/src/field/FunctionField.tsx index 298ee1e779a..7b28ccac2d7 100644 --- a/packages/ra-ui-materialui/src/field/FunctionField.tsx +++ b/packages/ra-ui-materialui/src/field/FunctionField.tsx @@ -18,9 +18,7 @@ import { FieldProps, fieldPropTypes } from './types'; * /> */ -export const FunctionField = < - RecordType extends Record = Record ->( +export const FunctionField = = any>( props: FunctionFieldProps ) => { const { className, source = '', render, ...rest } = props; @@ -49,7 +47,7 @@ FunctionField.propTypes = { }; export interface FunctionFieldProps< - RecordType extends Record = Record + RecordType extends Record = any > extends FieldProps, Omit { render: (record?: RecordType, source?: string) => any;