Effect CommunityEC
Effect Community2y ago
36 replies
danielo515

Question on Type Narrowing in TypeScript

Can someon explain me why this is not narrowed to an array of BroadcastSchema ??
import * as A from "effect/Array";
function foo(){
    return pipe(
      $events,
      A.filter((i) => BroadcastSchema.is(i)),
    );
}

Where the schema is defined as:
export class BroadcastSchema extends S.Class<BroadcastSchema>("Broadcast")(
  { type: S.Literal("fireworks", "confetti", "vivan los novios") },
) {
  static decode = S.decodeEither(this);
  static encode = S.encode(this);
  static make(fields: ConstructorParameters<typeof BroadcastSchema>[0]) {
    return new BroadcastSchema(fields);
  }
  static is = S.is(this);
  static Payload = this;
}
Was this page helpful?