can-define
can-define copied to clipboard
Proposal: Expanded Types and Required Properties
tldr
To make can-define
more useful and add some long-requested functionality, we will:
- add support for things like
prop: String
- expand the available
Type
s - add strict
Type
s - add support for
required
properties
This was discussed on a recent live stream (28:12)
Details
Allow shorthand with built-in Constructors
Instead of type: "string"
, type: "number"
, etc we should add support for using built-in constructors with Type
like:
var VM = can.DefineMap.extend({
prop: String
});
More Types
Also, we should add additional types. This is not a definitive list, just some things that have been requested and others that exist in other languages:
- float
- integer
- character
- Set
- enum / union
- tuple
Strict Types
We could also create strict types that would throw errors if set to a value of a different type. This might look something like:
import { StrictString } from 'can-define-strict-types';
import DefineMap from 'can-define/map/map';
const VM = DefineMap.extend({
prop: StrictString
});
This may also be called MustString
or something like that... we can bikeshed on naming later.
Required Values
Tangentially related to Types, people have also asked for support for required properties. While expanding the Type behavior, we would also add support for this.
@christopherjbaker pointed out that we should take a look at https://www.npmjs.com/package/prop-types for inspiration.