Releases: canjs/can-type
Documentation: Fix maybeConvert CodePen example
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
Update from maybe
to maybeConvert
in the documentation.
Adding steal-remove
Add type error property
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
.
Documentation improvements and type.Integer fixes
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 toNaN
but that is not a valid integer according toNumber.isInteger
so this has been changed to convert to0
instead.
Prevents running error message tests in production
This is just to fix the canjs/canjs build.
type.Integer
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
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
First major release
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