A
arktype2mo 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
Dimava2mo 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
PIat2mo ago
Is it possible to make the key completely optional?
Dimava
Dimava2mo ago
Wym
PIat
PIat2mo ago
Ooooooh You can put '?' directly in the key
Dimava
Dimava2mo ago
Yep just ?
PIat
PIat2mo ago
Perfect, it works, thank you a lot, @Dimava!
Want results from more Discord servers?
Add your server