thoughtspile / banditypes

🤠🧨 The mighty 400-byte schema validator for TS / JS
MIT License
168 stars 5 forks source link

[Bug] TS-first schemas allow stricter-than-needed checks #9

Open thoughtspile opened 1 year ago

thoughtspile commented 1 year ago

When using TS-first collection schemas, the field validations can be stricter than the type passed:

array<string>(enums(['s']))
array<{ key: string }>(object({ key: string(), extra: string() }))
object<{ key: string }>({
  key: enums(['s'])
})

This never results in incorrect runtime values, but can make authoring and maintaining schemas a bit more daunting and cause false negatives. In the case of nested objects, I'm pretty sure there's no way to disallow extra keys with current TS.

jordan-boyer commented 1 year ago

I'm not sure how to tackle this one if you have an idea let me know and i'll try to help implement it =)

thoughtspile commented 1 year ago

I have no ideas either. At this point it's probably best to add a note about nested objects in the docs