You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you attempt to parse this in TypeScript, it will give you errors such as
Property 'ifModifiedSince' of type 'number | undefined' is not assignable to 'string' index type 'string[] | undefined'.ts(2411)
This is occurring because additionalProperties is telling the object that all of its values should be string[], as opposed to just unlisted values.
Expected result
I don't know what the expected result should be honestly, but this doesn't compile so certainly not this. I'm not sure if this is a limitation of TypeScript as a language, if it is, maybe just generate something like [key: string]: unknown?
Checklist
My OpenAPI schema passes the Redocly validator (npx @redocly/cli@latest lint)
This is a known issue and 7.x will NOT have | undefined for this very reason. It originally meant to improve type safety and discourage use of additionalProperties, but has caused issues in 6.x. Changing this would be a breaking change for many people, so it’s saved for the next major release.
This is already largely captured in #1055 (and other discussions); feel free to add to additional issues with more info if you’d like.
Description
When provided a schema that has additional properties, the generated TypeScript generates a "catch-all" key-value pair that causes compile errors.
openapi-typescript
6.7.5
20.11.0
macOS 14
Reproduction
Here is the JSON I'm converting
And here is the outputted TypeScript code:
If you attempt to parse this in TypeScript, it will give you errors such as
This is occurring because additionalProperties is telling the object that all of its values should be string[], as opposed to just unlisted values.
Expected result
I don't know what the expected result should be honestly, but this doesn't compile so certainly not this. I'm not sure if this is a limitation of TypeScript as a language, if it is, maybe just generate something like
[key: string]: unknown
?Checklist
npx @redocly/cli@latest lint
)The text was updated successfully, but these errors were encountered: