Chalarangelo/jsiqle

Make all types required by default

Chalarangelo opened this issue · 1 comments

Motivation

Type definitions are not necessarily intuitive or very useful as they stand right now. It would be easier to rewrite the API in a way that makes more sense and give more control to developers.

Proposal

Deprecate all Required-suffixed field types. Types will now be simpler and easier to use. Their behavior should be as follows:

  • The value of a type (e.g. string) must either match the type or be null.
  • undefined is strictly prohibited for all types and will throw an error.
  • defaultValue is null everywhere by default.
  • If a different defaultValue is provided, record attributes will use it when they are defined.

This makes it so that fields are more intuitive and developers are forced to provide sensible defaults if they need to do so.

A non-emptiness validator should be added to disallow null shall the user desire to do so. This effectively allows previously required types to be converted to a non-required one with a sensible defaultValue and the non-null validator in place.

Considerations

As part of investigating and implementing this, we can consider the possibility that defaultValue could be useful as a function. This way dynamic defaults can be passed to fields at record initialization.

Resolved in #28