Open atomanyih opened 2 years ago
I agree with this I think the same can be concept can be applied to .oneOf
// A
class StringPredicate extends Predicate<string> {
oneOf<S extends string>(expected: S[]): Predicate<S>;
}
// B
class StringPredicate<S extends string> extends Predicate<S> {
oneOf<S2 extends string>(expected: S2[]): StringPredicate<S2>;
}
Problem
Use case: validating tagged json objects coming over the wire
Current workaround:
As far as I could tell, there's no built in way to do this as
StringPredicate#addValidator
andStringPredicate#validate
don't seem to let you change the type contained in the predicate.So, I created a custom predicate:
Possible solutions:
A. Generify
ow.string.equals
Currently this doesn't allow any further narrowing:
It could possibly be:
This does prevent any further chaining onto that predicate, but one could argue that a string matching
equals
cannot be further validated. Certainly none of the other included validators can give you any more useful informationB. Generify
StringPredicate
If one wanted to maintain chaining, could do something like this:
Thus the returned type would still be a
StringPredicate
.C. Some other better solution ? ? ?