all
Derive a new type that changes the types of properties using a converter function.
type.all(converter, Type)
Create a new type that inherits the same properties of Type
, but with each property run through the converter function. The converter function should be one of check, maybe, convert, or maybeConvert.
import { ObservableObject, Reflect, type } from "can/everything";
class Person extends ObservableObject {
static props = {
age: Number
}
}
// Age is a strict number.
let person = new Person();
try {
person.age = "13";
} catch(err) {
console.log("Oops, tried to convert a strict type.");
}
let ConvertingPerson = type.all(type.convert, Person);
person = Reflect.new(Person);
person.age = "13";
console.log("Age is", person.age); // logs 13
Parameters
- converter
{check(Type)|maybe(Type)|convert(Type)|maybeConvert(Type)}
:One of check, maybe, convert, or maybeConvert.
- Type
{function}
:Any type with a getSchema implementation.