Skip to content

Commit 05179fd

Browse files
committed
fix(renderer): improve schema type inference
1 parent 30b7512 commit 05179fd

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

packages/react-form-renderer/src/form-renderer/form-renderer.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface FormRendererProps<
2929
onReset?: () => void;
3030
onError?: (...args: any[]) => void;
3131
onSubmit?: FormProps<FormValues, InitialFormValues>['onSubmit'];
32-
schema: Schema;
32+
schema: Schema | (Record<string, any> & { fields: Array<Record<string, any>> });
3333
clearOnUnmount?: boolean;
3434
clearedValue?: any;
3535
componentMapper: ComponentMapper;
@@ -107,7 +107,7 @@ function FormRenderer<
107107
...props
108108
}: FormRendererProps<FormValues, InitialFormValues, FTP>): ReactElement<any, any> {
109109
const [fileInputs, setFileInputs] = useState<string[]>([]);
110-
const formFields = useMemo(() => renderForm(schema.fields), [schema]);
110+
const formFields = useMemo(() => renderForm(schema.fields as any), [schema]);
111111
const registeredFields = useRef<Record<string, number>>({});
112112
const focusDecorator = useRef(createFocusDecorator());
113113
const validatorMapperMerged = useMemo(() => {
@@ -187,7 +187,7 @@ function FormRenderer<
187187
const validatorTypes = Object.keys(validatorMapperMerged);
188188
const actionTypes = actionMapper ? Object.keys(actionMapper) : [];
189189

190-
defaultSchemaValidator(schema, componentMapper, validatorTypes, actionTypes, schemaValidatorMapper);
190+
defaultSchemaValidator(schema as any, componentMapper, validatorTypes, actionTypes, schemaValidatorMapper);
191191
} catch (error: any) {
192192
handleErrorCallback('schema-error', error);
193193
return <SchemaErrorComponent name={error.name} message={error.message} />;
@@ -230,13 +230,13 @@ function FormRenderer<
230230
ffGetRegisteredFields: form.getRegisteredFields,
231231
getRegisteredFields: internalGetRegisteredFields,
232232
initialValues,
233-
schema,
233+
schema: schema as any,
234234
},
235235
}}
236236
>
237-
{FormTemplate && <FormTemplate {...({ formFields, schema, ...FormTemplateProps } as FTP)} />}
237+
{FormTemplate && <FormTemplate {...({ formFields, schema: schema as any, ...FormTemplateProps } as FTP)} />}
238238

239-
{children && renderChildren(children, { formFields, schema })}
239+
{children && renderChildren(children, { formFields, schema: schema as any })}
240240
</RendererContext.Provider>
241241
)}
242242
{...props}

packages/react-form-renderer/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ export * from './use-form-api';
4444
export * from './validator-mapper';
4545
export * from './validator-types';
4646
export * from './validators';
47-
export * from './wizard-context';
47+
export * from './wizard-context';

packages/react-form-renderer/src/wizard-context/wizard-context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext } from 'react';
1+
import { createContext, KeyboardEvent } from 'react';
22
import { Field } from '../common-types';
33
import { FormOptions } from '../renderer-context';
44

@@ -19,7 +19,7 @@ export interface WizardContextValue {
1919
crossroads: string[];
2020
currentStep: { fields?: Field[]; name: string; title?: string; nextStep?: NextStep; isProgressAfterSubmissionStep?: boolean } | undefined;
2121
handlePrev: Function;
22-
onKeyDown: Function;
22+
onKeyDown?: (e: KeyboardEvent) => void;
2323
jumpToStep: Function;
2424
setPrevSteps: () => void;
2525
handleNext: Function;

0 commit comments

Comments
 (0)