| 6284 | return Object.assign(self, { cases, discriminants, isAnyOf, guards, match }) as any |
| 6285 | |
| 6286 | function walk(schema: Constraint) { |
| 6287 | const ast = schema.ast |
| 6288 | |
| 6289 | if ( |
| 6290 | SchemaAST.isUnion(ast) && "members" in schema && globalThis.Array.isArray(schema.members) && |
| 6291 | schema.members.every(isSchema) |
| 6292 | ) { |
| 6293 | return schema.members.forEach(walk) |
| 6294 | } |
| 6295 | |
| 6296 | const sentinels = SchemaAST.collectSentinels(ast) |
| 6297 | if (sentinels.length > 0) { |
| 6298 | const literal = sentinels.find((s) => s.key === tag)?.literal |
| 6299 | if (Predicate.isPropertyKey(literal)) { |
| 6300 | const key = typeof literal === "number" ? globalThis.String(literal) : literal |
| 6301 | if (discriminantKeys.has(key)) { |
| 6302 | throw new globalThis.Error(`Duplicate discriminant: ${globalThis.String(literal)}`) |
| 6303 | } |
| 6304 | discriminantKeys.add(key) |
| 6305 | discriminants.push(literal) |
| 6306 | InternalRecord.assignProperty(cases, literal, schema) |
| 6307 | InternalRecord.assignProperty(guards, literal, is(toType(schema))) |
| 6308 | return |
| 6309 | } |
| 6310 | } |
| 6311 | |
| 6312 | throw new globalThis.Error("No literal or unique symbol found") |
| 6313 | } |
| 6314 | |
| 6315 | function match() { |
| 6316 | if (arguments.length === 1) { |