Issue with renaming property in union schema

why does this not work?

const EndedSubscription = Schema.Struct({
  ended_at: Schema.Number,
});

const OngoingSubscription = Schema.Struct({
  ended_at: Schema.Null,
});

export const Subscription = Schema.Union(
  EndedSubscription.pipe(
    Schema.attachPropertySignature('kind', 'EndedSubscription'),
  ),
  OngoingSubscription.pipe(
    Schema.attachPropertySignature('kind', 'OngoingSubscription'),
  ),
).pipe(
  Schema.rename({
    ended_at: 'endedAt',
  }),
);


 FAIL  src/lib/stripe.test.ts [ src/lib/stripe.test.ts ]
Error: rename: cannot rename (({ readonly ended_at: number } <-> { readonly kind: "EndedSubscription"; readonly ended_at: number }) | ({ readonly ended_at: null } <-> { readonly ended_at: null; readonly kind: "OngoingSubscription" }))
 ❯ Module.rename ../../node_modules/.pnpm/@effect+schema@0.67.12_effect@3.2.4/node_modules/@effect/schema/src/AST.ts:2612:9
 ❯ body ../../node_modules/.pnpm/@effect+schema@0.67.12_effect@3.2.4/node_modules/@effect/schema/src/Schema.ts:3503:66
 ❯ Arguments.<anonymous> ../../node_modules/.pnpm/effect@3.2.4/node_modules/effect/src/Function.ts:102:18
 ❯ pipeArguments ../../node_modules/.pnpm/effect@3.2.4/node_modules/effect/src/Pipeable.ts:293:21
 ❯ Function.pipe ../../node_modules/.pnpm/@effect+schema@0.67.12_effect@3.2.4/node_modules/@effect/schema/src/Schema.ts:105:14
 ❯ src/lib/stripe.ts:20:3
     18|     Schema.attachPropertySignature('kind', 'OngoingSubscription'),
     19|   ),
     20| ).pipe(
       |   ^
     21|   Schema.rename({
     22|     ended_at: 'endedAt',
Was this page helpful?