ThomasAribart / json-schema-to-ts

Infer TS types from JSON schemas 📝
MIT License
1.4k stars 30 forks source link

Why does `FromSchema` on an object schema allow any properties `[x: string]: unknown` on the type? #205

Closed aentwist closed 1 week ago

aentwist commented 1 week ago

This goes against TS, I'd prefer objects of known and well-defined types to not accept additional fields that don't exist. If I wanted a subtype I'd explicitly declare it. What was the design choice with this?

ThomasAribart commented 1 week ago

@aentwist Yes, this is a design choice. This reminds you that JSON Schemas do not deny additional properties by default.

You can remove it by using additionalProperties: false, or unevaluatedProperties: false.

aentwist commented 1 week ago

Thank you for the fantastic answer. I appreciate it.