A small library for building and checking types in typst.
t_assert(type, value)
panics if the given value is not of the specified type. Returns nothing.t_check(type, value)
checks if the given value if of the specified type and returnstrue
if it ist_require(type, value)
panics if the given value is not of the specified type. Returns the value if no panic.
TBoolean
primtive typeTInteger
primtive typeTFloat
primtive typeTLength
primtive typeTAngle
primtive typeTRatio
primtive typeTRelativeLength
primtive typeTFraction
primtive typeTColor
primtive typeTSymbol
primtive typeTString
primtive typeTContent
primtive typeTFunction
primtive type
TAny
allows everythingTNone
none literalTNumber
or combination ofTInteger
andTFloat
TLit(lit)
literal type. Allowes only the given literal as type.TMap(values)
generic map from string tovalue
TDict(..fields)
generic dictionary with the given fields. Only named fields are allowedTArray(values)
generic array with zero or more values of one typeTTuple(..elemn)
generic tuple of exact size. Only positional fields are allowed
t_or(..types)
constructs a union type of all given typesoptional(type)
used to make a dictionary field optional
#import "types_for_typst.typ": *
#t_assert(TInteger, 7)
#t_assert(TNumber, 4.2)
#t_assert(TArray(TString), ())
#t_assert(TArray(TString), ("Test",))
#t_check(TArray(TNumber), (4.7, 1, "Test"))
#t_check(TArray(TString), ("Test", 8))
#t_check(TDict(test: TNumber, name: TString, sym: optional(TSymbol)), (test: "d", name: [OK], extra: 42))
#t_assert(TTuple(TNumber, TString, TDict(r: TRatio, num: TNumber)), (42, "LUL", (r: 50%, num: 8)))
#t_check(TMap(t_or(TString, TContent)), (l: "OK", b: [sdf], c: 8))
#t_assert(t_or(TLit("mon"), TLit("two"), TLit("three"), TLit(42)), 42)