late
Define a function that returns a type.
type.late(fn)
Given a function, returns a TypeObject that will unwrap to the underlying type provided within fn
.
import { ObservableObject, type } from "can/everything";
class Faves extends ObservableObject {
static props = {
faves: type.late(() => type.convert(Faves))
}
}
let faves = new Faves({
faves: {}
});
console.log("faves.faves is a Faves?", faves.faves instanceof Faves);
Parameters
- fn
{function}
:A function that when called returns a TypeObject.
Returns
{TypeObject}
:
A TypeObject that also includes a can.unwrapType
symbol that returns the underlying TypeObject.
Use
type.late
provides a way to define types when a binding is not immediately available. This could be because:
- You have cyclical types, such that A has a property for B and B has a property for A.
- You have a type with a property whos type is itself.
In both of these cases, type.late
provides a way to define the underlying type.