Skip to main content
Version: Current (v7.0.0-beta.3)

A bare UiSchema no longer fits a form whose data has a narrow index signature

Detect​

  • In your code: a bare UiSchema or a UiSchema<GenericObjectType> passed as the uiSchema of a Form whose formData is a Record<string, string>, a Record<string, string>[] or similar.
  • In your code: a UiSchema<{ meta: any }> used where a UiSchema<{ meta: string }>, or any other type for meta, is expected.
  • The type checker reports Type '…' is not assignable to type '…'. (TS2322) on that uiSchema.

Change​

Each key of that index signature holds a UiSchema for its value, which the unknown entries of an untyped UiSchema don't fit; see Entries read from an untyped UiSchema are unknown. A Record<string, unknown> target is fine, since its entries are as open as the untyped one's. Annotate the uiSchema with the data it describes:

-const uiSchema: UiSchema = { notes: { 'ui:widget': 'textarea' } };
+const uiSchema: UiSchema<Record<string, string>> = { notes: { 'ui:widget': 'textarea' } };

Verify​

  • The type checker accepts the uiSchema on the form.
  • Nothing changes at runtime.

Also read: