$match Type Error in Tagged Union Example
The new $match is a bit too strict imo. Take this as an example:
type Forms = S.Schema.Type<typeof Forms>;
const Forms = S.Union(
S.Struct({
_tag: S.Literal("UpdatePassword"),
currentPassword: Password.Plaintext,
password: Password.Strong,
password2: Password.Strong,
}),
S.Struct({
_tag: S.Literal("SetPassword"),
password: Password.Strong,
password2: Password.Strong,
}),
);
const match = Match.typeTags<Forms>();
const { $match } = Data.taggedEnum<Forms>();
// Type error
// Type 'Effect<never, CredentialAlreadyInUse, never>' is not assignable to type 'Effect<never, CredentialNotRecognised, never>
S.decodeUnknown(Forms)({}).pipe(
Effect.flatMap(
$match({
SetPassword: (a) => Effect.fail(new CredentialNotRecognised()),
UpdatePassword: (a) => Effect.fail(new CredentialAlreadyInUse()),
}),
),
);
// No error
S.decodeUnknown(Forms)({}).pipe(
Effect.flatMap(
match({
SetPassword: (a) => Effect.fail(new CredentialNotRecognised()),
UpdatePassword: (a) => Effect.fail(new CredentialAlreadyInUse()),
}),
),
);type Forms = S.Schema.Type<typeof Forms>;
const Forms = S.Union(
S.Struct({
_tag: S.Literal("UpdatePassword"),
currentPassword: Password.Plaintext,
password: Password.Strong,
password2: Password.Strong,
}),
S.Struct({
_tag: S.Literal("SetPassword"),
password: Password.Strong,
password2: Password.Strong,
}),
);
const match = Match.typeTags<Forms>();
const { $match } = Data.taggedEnum<Forms>();
// Type error
// Type 'Effect<never, CredentialAlreadyInUse, never>' is not assignable to type 'Effect<never, CredentialNotRecognised, never>
S.decodeUnknown(Forms)({}).pipe(
Effect.flatMap(
$match({
SetPassword: (a) => Effect.fail(new CredentialNotRecognised()),
UpdatePassword: (a) => Effect.fail(new CredentialAlreadyInUse()),
}),
),
);
// No error
S.decodeUnknown(Forms)({}).pipe(
Effect.flatMap(
match({
SetPassword: (a) => Effect.fail(new CredentialNotRecognised()),
UpdatePassword: (a) => Effect.fail(new CredentialAlreadyInUse()),
}),
),
);