|
| 1 | +--- |
| 2 | +"@evolution-sdk/evolution": patch |
| 3 | +--- |
| 4 | + |
| 5 | +Improve `Variant` type inference with `PropertyKey` constraint |
| 6 | + |
| 7 | +The `Variant` helper now accepts `PropertyKey` (string | number | symbol) as variant keys instead of just strings, enabling more flexible discriminated union patterns. |
| 8 | + |
| 9 | +**Before:** |
| 10 | +```typescript |
| 11 | +// Only string keys were properly typed |
| 12 | +const MyVariant = TSchema.Variant({ |
| 13 | + "Success": { value: TSchema.Integer }, |
| 14 | + "Error": { message: TSchema.ByteArray } |
| 15 | +}) |
| 16 | +``` |
| 17 | + |
| 18 | +**After:** |
| 19 | +```typescript |
| 20 | +// Now supports symbols and numbers as variant keys |
| 21 | +const MyVariant = TSchema.Variant({ |
| 22 | + Success: { value: TSchema.Integer }, |
| 23 | + Error: { message: TSchema.ByteArray } |
| 24 | +}) |
| 25 | +// Type inference is improved, especially with const assertions |
| 26 | +``` |
| 27 | + |
| 28 | +Replace `@ts-expect-error` with `as any` following Effect patterns |
| 29 | + |
| 30 | +Improved code quality by replacing forbidden `@ts-expect-error` directives with explicit `as any` type assertions, consistent with Effect Schema's approach for dynamic object construction. |
| 31 | + |
| 32 | +Add comprehensive Cardano Address type support |
| 33 | + |
| 34 | +Added full CBOR encoding support for Cardano address structures with Aiken compatibility: |
| 35 | + |
| 36 | +```typescript |
| 37 | +const Credential = TSchema.Variant({ |
| 38 | + VerificationKey: { hash: TSchema.ByteArray }, |
| 39 | + Script: { hash: TSchema.ByteArray } |
| 40 | +}) |
| 41 | + |
| 42 | +const Address = TSchema.Struct({ |
| 43 | + payment_credential: Credential, |
| 44 | + stake_credential: TSchema.UndefinedOr( |
| 45 | + TSchema.Variant({ |
| 46 | + Inline: { credential: Credential }, |
| 47 | + Pointer: { |
| 48 | + slot_number: TSchema.Integer, |
| 49 | + transaction_index: TSchema.Integer, |
| 50 | + certificate_index: TSchema.Integer |
| 51 | + } |
| 52 | + }) |
| 53 | + ) |
| 54 | +}) |
| 55 | + |
| 56 | +// Creates proper CBOR encoding matching Aiken's output |
| 57 | +const address = Data.withSchema(Address).toData({ |
| 58 | + payment_credential: { VerificationKey: { hash } }, |
| 59 | + stake_credential: { Inline: { credential: { VerificationKey: { stakeHash } } } } |
| 60 | +}) |
| 61 | +``` |
0 commit comments