wynn/ts/scratch/test.ts

21 lines
461 B
TypeScript
Raw Normal View History

2025-06-14 23:04:46 +00:00
import { ArkErrors, type } from 'arktype'
2025-02-27 03:56:30 +00:00
2025-06-14 23:04:46 +00:00
const tupleType = type(['number', 'string'])
2025-02-27 03:56:30 +00:00
const tupleArrayType = tupleType.array()
const unionType = tupleType.or(tupleArrayType)
// good
2025-06-14 23:04:46 +00:00
tupleType.assert([1, '2'])
2025-02-27 03:56:30 +00:00
// good
2025-06-14 23:04:46 +00:00
tupleArrayType.assert([[1, '2']])
2025-02-27 03:56:30 +00:00
// no good!
2025-06-14 23:04:46 +00:00
const resp = unionType([[1, '2']])
if (resp instanceof ArkErrors) {
2025-02-27 03:56:30 +00:00
const err = resp[0]
console.log(err.data)
console.log(err.problem)
console.log(err.message)
console.log(err.path)
}