ostrowr / ts-json-validator

Let JSON play nicely with Typescript
MIT License
342 stars 7 forks source link

[Request] Add test/example for IfThenElseConstraint #44

Closed mdurling closed 3 years ago

mdurling commented 3 years ago

I am trying to use this library with TS 4.1.3. It would be super helpful if the library contained tests or an example on how to use some of the more advanced JSON Schema features, in particular the IfThenElseConstraint

mdurling commented 3 years ago

@ostrowr I think there may be a slight problem with the types for If, Then, and Else. The current types:

if?: Then extends SchemaLike ? SchemaLike : Else extends SchemaLike ? SchemaLike : never;
then?: If extends SchemaLike ? SchemaLike : never;
else?: If extends SchemaLike ? SchemaLike : never;

Are causing tsc errors which resolve if I change the definitions as follows:

if?: Then extends SchemaLike ? If : Else extends SchemaLike ? If : never;
then?: If extends SchemaLike ? Then : never;
else?: If extends SchemaLike ? Else : never;
ostrowr commented 3 years ago

closed by #45

ostrowr commented 3 years ago

This is fixed in 0.7.1.