Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Expanded Types and Required Properties #287

Open
phillipskevin opened this issue Nov 3, 2017 · 1 comment
Open

Proposal: Expanded Types and Required Properties #287

phillipskevin opened this issue Nov 3, 2017 · 1 comment

Comments

@phillipskevin
Copy link
Contributor

phillipskevin commented Nov 3, 2017

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 Types
  • add strict Types
  • 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.

@phillipskevin phillipskevin changed the title Proposal: expand Type functionality Proposal: Expanded Types and Required Properties Nov 3, 2017
@phillipskevin
Copy link
Contributor Author

@christopherjbaker pointed out that we should take a look at https://www.npmjs.com/package/prop-types for inspiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant