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

getDefaultFormState fills a missing null-typed value as null

Detect​

  • Calls to getDefaultFormState() or schemaUtils.getDefaultFormState() in your code, on a schema with a type: 'null' property.
  • Code that assigns the result to a type that excludes null.

Change​

getDefaultFormState() now fills in a missing type: 'null' value as null, the same as the form does (see Form no longer calls onChange on mount for defaults or null fields). The exception is an anyOf/oneOf option that is rendered, unless its field is required. Its return type now includes null, so narrow the result before you use it:

-const defaults: MyData = schemaUtils.getDefaultFormState(schema, formData);
+const defaults = schemaUtils.getDefaultFormState(schema, formData) ?? {};

Verify​

  • The type checker accepts each use of the result.
  • Code that tests for a missing type: 'null' key now expects the key to hold null.

Also read: