|
| 1 | +import { |
| 2 | + Schema, |
| 3 | + SchemaSimpleEnum, |
| 4 | + SchemaMixedEnum, |
| 5 | + SchemaEnumWithObject, |
| 6 | + SchemaEnumWithArray |
| 7 | +} from "./expected"; |
| 8 | + |
| 9 | + |
| 10 | +// Valid: simple string enum values |
| 11 | +const simple1: SchemaSimpleEnum = "foo"; |
| 12 | +const simple2: SchemaSimpleEnum = "bar"; |
| 13 | +const simple3: SchemaSimpleEnum = "baz"; |
| 14 | + |
| 15 | +// Invalid: wrong string for simple enum |
| 16 | +// @ts-expect-error - must be "foo" | "bar" | "baz" |
| 17 | +const simpleInvalid: SchemaSimpleEnum = "invalid"; |
| 18 | + |
| 19 | +// Valid: mixed enum values |
| 20 | +const mixed1: SchemaMixedEnum = "active"; |
| 21 | +const mixed2: SchemaMixedEnum = 42; |
| 22 | +const mixed3: SchemaMixedEnum = true; |
| 23 | +const mixed4: SchemaMixedEnum = null; |
| 24 | + |
| 25 | +// Invalid: wrong value for mixed enum |
| 26 | +// @ts-expect-error - must be "active" | 42 | true | null |
| 27 | +const mixedInvalid: SchemaMixedEnum = "inactive"; |
| 28 | + |
| 29 | +// Valid: enum with object value |
| 30 | +const withObj1: SchemaEnumWithObject = "simple"; |
| 31 | +const withObj2: SchemaEnumWithObject = { type: "complex", value: 123 }; |
| 32 | + |
| 33 | +// Invalid: completely wrong type for enum with object |
| 34 | +// @ts-expect-error - must be "simple" or the exact object literal |
| 35 | +const withObjInvalid: SchemaEnumWithObject = "wrong"; |
| 36 | + |
| 37 | +// Valid: enum with array value |
| 38 | +const withArr1: SchemaEnumWithArray = 1; |
| 39 | +const withArr2: SchemaEnumWithArray = [ 1, 2, 3 ]; |
| 40 | + |
| 41 | +// Invalid: wrong array |
| 42 | +// @ts-expect-error - must be exactly [1, 2, 3] |
| 43 | +const withArrInvalid: SchemaEnumWithArray = [ 1, 2 ]; |
| 44 | + |
| 45 | +// Valid: full schema object |
| 46 | +const fullSchema: Schema = { |
| 47 | + simpleEnum: "foo", |
| 48 | + mixedEnum: 42, |
| 49 | + enumWithObject: { type: "complex", value: 123 }, |
| 50 | + enumWithArray: [ 1, 2, 3 ] |
| 51 | +}; |
| 52 | + |
| 53 | +// Valid: partial schema |
| 54 | +const partialSchema: Schema = { |
| 55 | + simpleEnum: "bar" |
| 56 | +}; |
| 57 | + |
| 58 | +// Valid: empty schema (all optional) |
| 59 | +const emptySchema: Schema = {}; |
0 commit comments