Nullable reference to another type

Hey! How can I reference other types that can be also null? Is it possible using the string syntax? I'm currently getting the "is unresolvable" error when I do type("OtherType | null") which makes sense.
3 Replies
0xAFFE
0xAFFE•2d ago
I do it that way:
type({
failureReason: FailureReasonSchema.or(type.null),
})
type({
failureReason: FailureReasonSchema.or(type.null),
})
Lubos from Hey API
Lubos from Hey APIOP•this hour
Do you start off with plain strings and in this type of case switch to the fluent syntax? What if instead of null it was a more complex string with length constraints? I'm working on a code generator for Arktype and trying to figure out what the most native output would look like It seems strings are desirable but for cases like this I need to maintain also the fluent syntax... in which case a question is in place, should I ALWAYS use the fluent syntax?
0xAFFE
0xAFFE•this hour
Hmm, you probably want to define a scope for your types: https://arktype.io/docs/scopes But I'm not that deep into ark yet and maybe @ssalbdivad should help me out 😉
ArkType
ArkType Docs
TypeScript's 1:1 validator, optimized from editor to runtime

Did you find this page helpful?