A
arktype5mo ago
PIat

Optional key

Hello! How can I define an array, which is also not required as an optional key? Is this the easiest way? https://discord.com/channels/957797212103016458/957804102685982740/1213198676349026355
// Goal:
{
steps?: ...[]
}

// This still needs `steps: undefined`
steps:
type({
key: "'first'",
})
.or({
key: "'second'",
})
.array()
.or('undefined')
// Goal:
{
steps?: ...[]
}

// This still needs `steps: undefined`
steps:
type({
key: "'first'",
})
.or({
key: "'second'",
})
.array()
.or('undefined')
6 Replies
Dimava
Dimava5mo ago
const T = type({
'steps?': [
[ { key: "'first'" }, '|', { key: "'second'" } ],
'[]',
],
})
const T = type({
'steps?': [
[ { key: "'first'" }, '|', { key: "'second'" } ],
'[]',
],
})
tl;dr if the chain definition is easier for you feel free to use it Don't or undefined tho, that may have different meaning
PIat
PIatOP5mo ago
Is it possible to make the key completely optional?
Dimava
Dimava5mo ago
Wym
PIat
PIatOP5mo ago
Ooooooh You can put '?' directly in the key
Dimava
Dimava5mo ago
Yep just ?
PIat
PIatOP5mo ago
Perfect, it works, thank you a lot, @Dimava!
Want results from more Discord servers?
Add your server