Currently, the additionalProperties keyword is ignored, and the Typescript type is generated in this way:
someObject: {}
If you are using typescript-eslint > v5.0.0, this will raise an error, because the empty object literal syntax is banned, as it is considered unsafe. Instead we should use:
someObject: Record<string, string>
In addition to the example shown above, there are other use cases for additionalProperties:
In an OpenAPI document, when an object has some dynamic keys, it's declared like so:
Currently, the additionalProperties keyword is ignored, and the Typescript type is generated in this way:
someObject: {}
If you are using
typescript-eslint
> v5.0.0, this will raise an error, because theempty object literal
syntax is banned, as it is considered unsafe. Instead we should use:someObject: Record<string, string>
In addition to the example shown above, there are other use cases for
additionalProperties
:If the dictionary values can be of any type (aka free-form object) -->
Record<string, unknown>
Instead of using an inline schema, additionalProperties can $ref another schema
When a dictionary has some fixed properties, and some dynamic ones.