-
-
Notifications
You must be signed in to change notification settings - Fork 633
Description
openapi-typescript version
7.13.0
Node.js version
24.x.x
OS + version
macOS 26.3.1
Description
When using enumValues: true together with immutable: true, the generated FlattenedDeepRequired utility type fails to flatten readonly arrays, producing type errors on the enum value exports.
immutable: true generates readonly arrays (readonly T[]). The FlattenedDeepRequired utility checks:
T[K] extends unknown[] | undefined | nullBut in TypeScript, readonly unknown[] does not extend unknown[] — readonly arrays are not assignable to mutable arrays. So the array-to-element flattening never triggers, and the indexed path (e.g. ["fields"]["name"]) fails because fields remains typed as an array instead of being flattened to its element type.
Related: PR #2139 improved FlattenedDeepRequired for optional props and arrays but didn't account for readonly arrays generated by immutable: true.
Reproduction
Given a schema with an enum nested inside an array property:
MatchingRuleFilterMetadata:
type: object
properties:
fields:
type: array
items:
type: object
properties:
name:
type: string
enum: [description, merchant_name, amount]Running with immutable: true and enumValues: true generates:
type FlattenedDeepRequired<T> = {
[K in keyof T]-?: FlattenedDeepRequired<T[K] extends unknown[] | undefined | null ? Extract<T[K], unknown[]>[number] : T[K]>;
};
export const matchingRuleFilterMetadataFieldsNameValues: ReadonlyArray<
FlattenedDeepRequired<components>["schemas"]["MatchingRuleFilterMetadata"]["fields"]["name"]
> = ["description", "merchant_name", "amount"];This produces:
error TS2339: Property 'name' does not exist on type 'readonly FlattenedDeepRequired<{ readonly name?: "description" | "merchant_name" | "amount" | undefined; ... }>[]'
Expected result
The generated enum value exports should compile without errors when immutable: true and enumValues: true are used together. FlattenedDeepRequired should correctly flatten readonly arrays to their element type, so that paths like ["fields"]["name"] resolve through the array to the element's properties.
Required
- My OpenAPI schema is valid and passes the Redocly validator (
npx @redocly/cli@latest lint)
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)