Skip to content

Incorrect tuple type inference for array items in response content#2702

Description

@oltodo

openapi-typescript version

7.12.0

Node.js version

22.x.x

OS + version

13.1

Description

Hi 馃憢

I鈥檓 running into an issue with type inference when using openapi-typescript together with openapi-fetch.

It seems that tuple types defined in the OpenAPI schema are widened to regular arrays in the generated types.

Reproduction

import createClient from "openapi-fetch";

interface operations {
  foo: {
    parameters: {
      query?: never;
      header?: never;
      path?: never;
      cookie?: never;
    };
    requestBody?: never;
    responses: {
      200: {
        headers: {
          [name: string]: unknown;
        };
        content: {
          "application/json": {
            data: {
              id: string | number;
              content: [{ foo: "" }];
            }[];
          };
        };
      };
      400: {
        headers: {
          [name: string]: unknown;
        };
        content?: never;
      };
      401: {
        headers: {
          [name: string]: unknown;
        };
        content?: never;
      };
      403: {
        headers: {
          [name: string]: unknown;
        };
        content?: never;
      };
      404: {
        headers: {
          [name: string]: unknown;
        };
        content?: never;
      };
      500: {
        headers: {
          [name: string]: unknown;
        };
        content?: never;
      };
    };
  };
}

interface paths {
  "/foo": {
    parameters: {
      query?: never;
      header?: never;
      path?: never;
      cookie?: never;
    };
    get: operations["foo"];
    put?: never;
    post: never;
    delete?: never;
    options?: never;
    head?: never;
    patch?: never;
    trace?: never;
  };
}

const client = createClient<paths>({ baseUrl: "" });

async function main() {
  const { data } = await client.GET("/foo");
  //      ^ `content` is typed as `{ foo: "" }[]`
}

Expected result

content should be typed as [{ foo: "" }]

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions