Schema Validation with Branded Types and Nominal Function in TypeScript

Hi, I tried the following code:
type TenFromSelf = Brand.Branded<number, 'TenFromSelf'>;
const unsafeFromNumber = Brand.nominal<TenFromSelf>();
const TenFromSelf: Schema.Schema<TenFromSelf> = Schema.declare((input: unknown): input is TenFromSelf => input === 10);

console.log(pipe(5, unsafeFromNumber, Schema.decodeEither(TenFromSelf), Either.isRight));

The output is
false
. If I replace 5 by 10, I get a
true
.

Of course, 5 is not a TenFromSelf. But I would expect the TenFromSelf schema not to check this. It gets a TenFromSelf as input and, in my opinion, it should trust the input to be what it pretends to be. Or am I missing something?

Of course, this example is a bit stupid. But I am working on a time consuming schema and realized that what I think are unnecessary tests were carried out. Hence this example.
Was this page helpful?