Fix issue with missing default values by tpaulshippy · Pull Request #773 · hotwired/stimulus

Purpose

Resolves issue #772
https://stimulus.hotwired.dev/reference/values#existential-properties states the following:

The existential property for a value evaluates to true when the associated data attribute is present on the controller’s element and false when it is absent.

The exception to this defined here is when a custom default value is provided. Defaults can be provided either as a literal, or with the default property like so: { type: String, default: 'abc' }.

Approach

  1. If the type is a constant, it does not have a default.
    Example: something: String
  2. If the type has a default property, it does have a default.
    Example: something: { type: String, default: 'abc' }
  3. If the type has a type property (but not a default property), it does not have a default.
    Example: something: { type: String }
  4. Finally, if the type is a literal, it does have a default.
    Example: something: 'abc'

Tests

Unit tests with Karma