A
arktype7mo 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
Dimava7mo 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
PIatOP7mo ago
Is it possible to make the key completely optional?
Dimava
Dimava7mo ago
Wym
PIat
PIatOP7mo ago
Ooooooh You can put '?' directly in the key
Dimava
Dimava7mo ago
Yep just ?
PIat
PIatOP7mo ago
Perfect, it works, thank you a lot, @Dimava!

Did you find this page helpful?