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

SchemaUtilsType gains constrainsAlike(), childFillOf(), getFieldDefault() and getFilledDefault()

Detect​

  • In your code, a class or object that implements SchemaUtilsType from @rjsf/utils, such as a test mock.
  • The type checker reports Type '{ … }' is missing the following properties from type 'SchemaUtilsType<…>': constrainsAlike, childFillOf, getFilledDefault, getFieldDefault (TS2739) on it, or Property 'getFieldDefault' is missing in type '{ … }' but required in type 'SchemaUtilsType<…>'. (TS2741) when only one is missing.

Change​

SchemaUtilsType gains four methods, which read a field's defaults under the form's own defaultFormStateBehavior from a FieldFill, what the defaults hand the field:

  • constrainsAlike(oldSchema, newSchema, oldFill, newFill)
  • childFillOf(schema, fill, key)
  • getFieldDefault(schema, fill)
  • getFilledDefault(schema, fill)

Its doesSchemaUtilsDiffer() takes a SchemaContext and the rootSchema: doesSchemaUtilsDiffer(context, rootSchema).

Add the four methods to your implementation. The simplest way is to delegate to an instance from createSchemaUtils():

+const real = createSchemaUtils(context, rootSchema);
const schemaUtils: SchemaUtilsType = {
...
+ constrainsAlike: real.constrainsAlike.bind(real),
+ childFillOf: real.childFillOf.bind(real),
+ getFieldDefault: real.getFieldDefault.bind(real),
+ getFilledDefault: real.getFilledDefault.bind(real),
};

Verify​

The type checker accepts your implementation.

Also read: