21 lines
461 B
TypeScript
21 lines
461 B
TypeScript
import { ArkErrors, type } from 'arktype'
|
|
|
|
const tupleType = type(['number', 'string'])
|
|
const tupleArrayType = tupleType.array()
|
|
const unionType = tupleType.or(tupleArrayType)
|
|
|
|
// good
|
|
tupleType.assert([1, '2'])
|
|
// good
|
|
tupleArrayType.assert([[1, '2']])
|
|
|
|
// no good!
|
|
const resp = unionType([[1, '2']])
|
|
if (resp instanceof ArkErrors) {
|
|
const err = resp[0]
|
|
console.log(err.data)
|
|
console.log(err.problem)
|
|
console.log(err.message)
|
|
console.log(err.path)
|
|
}
|