A
arktype4w ago
Bert

Test that a string contains a substring?

Test that a string contains a substring?
5 Replies
Bert
BertOP4w ago
arkType([
{ status: '"Event Completed"', message: 'string' },
':',
r => r.message.includes('test')
]).assert(result)
arkType([
{ status: '"Event Completed"', message: 'string' },
':',
r => r.message.includes('test')
]).assert(result)
Best approach?
Dimava
Dimava4w ago
If the substring is simple and constant the best way may be regex
type({
message:/test/
// maybe also as type.as<`${string}test${string}`> if you need that lol
})
type({
message:/test/
// maybe also as type.as<`${string}test${string}`> if you need that lol
})
Bert
BertOP4w ago
ah that's cool
Dimava
Dimava4w ago
I don't recommend narrowing objects unless you mean it Your example needs tuple under message:['string', '=>',... ] Yep regex also gives a free explanation In error messages
Bert
BertOP4w ago
Yeah, it works, but it could be written better Thanks
Want results from more Discord servers?
Add your server