ostrowr / ts-json-validator

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

fix(additionalProperties): treat additionalProperties as optional #31

Closed bigpopakap closed 4 years ago

bigpopakap commented 4 years ago

I'm not 100% sure about this change, but it occurred to me while I was working on #30.

Should additionalProperties be treated as optional (as in, with a Partial<...>)? Because after parsing an object, you can't actually be sure in the type system whether parsedObject.someAdditionalProperty is defined or not.

One problem I can think of is that it softens the restriction when using additionalProperties: S(false), because it'll enforce Partial<{ [k: string]: never }> instead of the stricter { [k: string]: never }.

Don't worry about a bunch of extra noise from me :) This will be my last PR for a little while and I thought I'd just put up this PR directly because it came up while working on #30 and I had the code written already.

ostrowr commented 4 years ago

Closing this because it's stale-ish, but feel free to reopen if you have more thoughts.

bigpopakap commented 4 years ago

Fair enough. I haven't found the time to come back to this. If/when I hopefully do get to play around with it, I can open up a new PR in the future. Sorry for leaving this open for so long!