Skip to content

Commit b89ed15

Browse files
committed
Fix inference types
1 parent f2af29e commit b89ed15

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

packages/ra-core/src/inference/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import getElementsFromRecords from './getElementsFromRecords';
22
import InferredElement from './InferredElement';
33

44
export * from './inferTypeFromValues';
5+
export * from './types';
56

67
export { getElementsFromRecords, InferredElement };

packages/ra-ui-materialui/src/detail/editFieldTypes.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { ReactNode } from 'react';
2+
import { ReactNode, ReactElement } from 'react';
33
import SimpleForm from '../form/SimpleForm';
44
import SimpleFormIterator from '../form/SimpleFormIterator';
55
import ArrayInput from '../input/ArrayInput';
@@ -12,9 +12,9 @@ import ReferenceArrayInput, {
1212
} from '../input/ReferenceArrayInput';
1313
import SelectInput from '../input/SelectInput';
1414
import TextInput from '../input/TextInput';
15-
import { InferredElement, InputProps } from 'ra-core';
15+
import { InferredElement, InferredTypeMap, InputProps } from 'ra-core';
1616

17-
export default {
17+
const editFieldTypes: InferredTypeMap = {
1818
form: {
1919
component: SimpleForm,
2020
representation: (
@@ -74,7 +74,7 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
7474
}">${children.getRepresentation()}</ReferenceInput>`,
7575
},
7676
referenceChild: {
77-
component: (props: InputProps) => (
77+
component: (props: { children: ReactNode } & InputProps) => (
7878
<SelectInput optionText="id" {...props} />
7979
), // eslint-disable-line react/display-name
8080
representation: () => `<SelectInput optionText="id" />`,
@@ -85,9 +85,9 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
8585
`<ReferenceArrayInput source="${props.source}" reference="${props.reference}"><TextInput source="id" /></ReferenceArrayInput>`,
8686
},
8787
referenceArrayChild: {
88-
component: (props: InputProps) => (
89-
<SelectInput optionText="id" {...props} />
90-
), // eslint-disable-line react/display-name
88+
component: (
89+
props: { children: ReactNode } & InputProps
90+
): ReactElement => <SelectInput optionText="id" {...props} />, // eslint-disable-line react/display-name
9191
representation: () => `<SelectInput optionText="id" />`,
9292
},
9393
richText: {
@@ -106,3 +106,5 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
106106
`<TextInput source="${props.source}" />`,
107107
},
108108
};
109+
110+
export default editFieldTypes;

packages/ra-ui-materialui/src/detail/showFieldTypes.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import RichTextField from '../field/RichTextField';
1212
import SimpleShowLayout, { SimpleShowLayoutProps } from './SimpleShowLayout';
1313
import TextField from '../field/TextField';
1414
import UrlField from '../field/UrlField';
15-
import { InferredElement, InputProps } from 'ra-core';
15+
import { InferredElement, InferredTypeMap, InputProps } from 'ra-core';
1616

17-
export default {
17+
const showFieldTypes: InferredTypeMap = {
1818
show: {
1919
component: (props: SimpleShowLayoutProps) => (
2020
<SimpleShowLayout {...props} />
@@ -71,7 +71,9 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
7171
`<ReferenceField source="${props.source}" reference="${props.reference}"><TextField source="id" /></ReferenceField>`,
7272
},
7373
referenceChild: {
74-
component: (props: InputProps) => <TextField source="id" {...props} />, // eslint-disable-line react/display-name
74+
component: (props: { children: ReactNode } & InputProps) => (
75+
<TextField source="id" {...props} />
76+
), // eslint-disable-line react/display-name
7577
representation: () => `<TextField source="id" />`,
7678
},
7779
referenceArray: {
@@ -80,7 +82,9 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
8082
`<ReferenceArrayField source="${props.source}" reference="${props.reference}"><TextField source="id" /></ReferenceArrayField>`,
8183
},
8284
referenceArrayChild: {
83-
component: (props: InputProps) => <TextField source="id" {...props} />, // eslint-disable-line react/display-name
85+
component: (props: { children: ReactNode } & InputProps) => (
86+
<TextField source="id" {...props} />
87+
), // eslint-disable-line react/display-name
8488
representation: () => `<TextField source="id" />`,
8589
},
8690
richText: {
@@ -99,3 +103,5 @@ ${children.map(child => ` ${child.getRepresentation()}`).join('\n')}
99103
`<UrlField source="${props.source}" />`,
100104
},
101105
};
106+
107+
export default showFieldTypes;

0 commit comments

Comments
 (0)