Skip to content

Releases: canjs/can-type

Documentation: Fix maybeConvert CodePen example

23 Sep 17:58
Compare
Choose a tag to compare

Fix the example to be used on CodePen correctly, before, it was used without type. which cause an error on CodePen.

Documentation: Fix maybeConvert function name in the signature

03 Aug 18:12
Compare
Choose a tag to compare

Update from maybe to maybeConvert in the documentation.

#56

Adding steal-remove

26 Nov 16:30
Compare
Choose a tag to compare

Add type error property

01 Nov 17:42
Compare
Choose a tag to compare

Adds .type property to the thrown error when checking the type, this property can be used to check wether the error is caused by can-type.

#49

Documentation improvements and type.Integer fixes

17 Oct 14:10
Compare
Choose a tag to compare

This fixes a couple of bugs in type.Integer

  • Fixes use with can-query-logic so you can do stuff like greater/less than comparing integers.
  • Fixes converting types like {} that don't have an obvious integer conversion. Used to convert to NaN but that is not a valid integer according to Number.isInteger so this has been changed to convert to 0 instead.

Prevents running error message tests in production

10 Oct 18:51
Compare
Choose a tag to compare

This is just to fix the canjs/canjs build.

type.Integer

10 Oct 17:49
Compare
Choose a tag to compare

This is a minor release that adds type.Integer as a convenient way to get an integer type. This is useful when you want to convert to whole, non-fractional numbers.

import { Reflect, type } from "can";

let ConvertingInteger = type.convert(type.Integer);
let val = Reflect.convert(12.1, ConvertingInteger);

console.log(val); // -> 12

Improve error message

09 Oct 16:15
Compare
Choose a tag to compare

Improve error message by including the type of the value being set:

class Person extends ObservableObject() {
   static get props() {
      return {
	age: type.check(Number)
      };
   }
}

var farah = new Person();
farah.age = '4';  // -> Uncaught Error: 4 (String) is not of type Number.

1.0.1

08 Oct 21:48
Compare
Choose a tag to compare

Add can-type to can-namespace

This patch release adds can-type to can-namespace so it is available on the global can object.

First major release

04 Oct 16:51
Compare
Choose a tag to compare

This is the first major release of can-type, a new package in CanJS that brings more control on typing to CanJS.

In can-define passing types always converts them to the provided type, like so:

import { DefineMap } from "can";

const Person = DefineMap.extend({
  first: "string",
  last: "string",
  age: "number"
});

let person = new Person({ first: "hello", last: "world", age: "13" });

With can-type you can now introduce strict types as well as converting types, giving you greater control. This is included by default with can-observable-object.

import { ObservableObject } from "can";

class Person extends ObservableObject {
  static props = {
    first: String,
    last: type.maybe(String),
    age: type.convert(Number),
  }
}

let person = new Person({ first: "Sam", age: "13" });
console.log(person.first, person.last, person.age);  // "Sam" undefined 13