Custom types are also known as "union types", "tagged unions" and "algebraic data types".
While typescript provides a way to have compile-time union types, they are no longer available at runtime, which means they can't be used for active behaviours (such as messages in wool/browser).
Basic usage
import{Type}from'wool/core';constIncrement=Type.custom('Increment');constDecrement=Type.custom('Decrement');letvalue=0;constmsg=Increment();Type.matchOn(msg,{[Increment](){value=value+1;},[Decrement](){value=value-1;},});console.log(value);// 1Parameters
import{Type}from'wool/core';constSetValue=Type.custom('SetValue',Type.int);constmsg=SetValue(42);Type.matchOn(msg,{// ...[SetValue](newValue){value=newValue;},});console.log(value);// 42import{String,Type}from'wool/core';constSetGreeting=Type.custom('SetGreeting',Type.string,Type.int)letvalue='Hi';constmsg=SetGreeting('Hello',3);Type.matchOn(msg,{[SetGreeting](greeting,times){value=String.repeat(greeting,times);},});console.log(value);// "HelloHelloHello"
Custom types are also known as "union types", "tagged unions" and "algebraic data types".
While typescript provides a way to have compile-time union types, they are no longer available at runtime, which means they can't be used for active behaviours (such as messages in
wool/browser).Basic usage
Parameters