---
title: "TypeScript"
description: "Learn about files generated with @hey-api/openapi-ts."
url: "https://heyapi.dev/docs/openapi/typescript/plugins/typescript"
---

TypeScript interfaces are located in the `types.gen.ts` file. This is the only file that does not impact your bundle size and runtime performance. It will get discarded during build time, unless you configured to emit runtime [enums](#enums).

## Installation

[Section titled “Installation”](#installation)

In your [configuration](https://heyapi.dev/openapi-ts/get-started), add `@hey-api/typescript` to your plugins and you’ll be ready to generate TypeScript artifacts. 🎉

openapi-ts.config.ts

```js
export default {
  input: 'hey-api/backend', // sign up at app.heyapi.dev
  output: 'src/client',
  plugins: [
    // ...other plugins
    '@hey-api/typescript',
  ],
};
```

Note

The `@hey-api/typescript` plugin might be implicitly added to your `plugins` if another plugin depends on it.

## Output

[Section titled “Output”](#output)

The TypeScript plugin will generate the following artifacts, depending on the input specification.

## Requests

[Section titled “Requests”](#requests)

A single request type is generated for each endpoint. It may contain a request body, parameters, and headers.

types.gen.ts

```ts
export type AddPetData = {
  body: {
    id?: number;
    name: string;
  };
  path?: never;
  query?: never;
  url: '/pets';
};
```

You can customize the naming and casing pattern for `requests` types using the `.name` and `.case` options.

## Responses

[Section titled “Responses”](#responses)

A single type is generated for all endpoint’s responses.

types.gen.ts

```ts
export type AddPetResponses = {
  200: {
    id?: number;
    name: string;
  };
};


export type AddPetResponse = AddPetResponses[keyof AddPetResponses];
```

You can customize the naming and casing pattern for `responses` types using the `.name` and `.case` options.

## Definitions

[Section titled “Definitions”](#definitions)

A type is generated for every reusable definition from your input.

types.gen.ts

```ts
export type Pet = {
  id?: number;
  name: string;
};
```

You can customize the naming and casing pattern for `definitions` types using the `.name` and `.case` options.

## Enums

[Section titled “Enums”](#enums)

By default, `@hey-api/typescript` will emit enums only as types. You may want to generate runtime artifacts. A good use case is iterating through possible field values without manually typing arrays. To emit runtime enums, set `enums` to a valid option.

* disabled

  openapi-ts.config.ts

  ```js
  export default {
    input: 'hey-api/backend', // sign up at app.heyapi.dev
    output: 'src/client',
    plugins: [
      // ...other plugins
      {
        enums: false, // default
        name: '@hey-api/typescript',
      },
    ],
  };
  ```

* javascript

  openapi-ts.config.ts

  ```js
  export default {
    input: 'hey-api/backend', // sign up at app.heyapi.dev
    output: 'src/client',
    plugins: [
      // ...other plugins
      {
        enums: 'javascript',
        name: '@hey-api/typescript',
      },
    ],
  };
  ```

* typescript

  openapi-ts.config.ts

  ```js
  export default {
    input: 'hey-api/backend', // sign up at app.heyapi.dev
    output: 'src/client',
    plugins: [
      // ...other plugins
      {
        enums: 'typescript',
        name: '@hey-api/typescript',
      },
    ],
  };
  ```

We recommend exporting enums as plain JavaScript objects. [TypeScript enums](https://www.typescriptlang.org/docs/handbook/enums.html) are not a type-level extension of JavaScript and pose [typing challenges](https://dev.to/ivanzm123/dont-use-enums-in-typescript-they-are-very-dangerous-57bh).

## Comments

[Section titled “Comments”](#comments)

By default, `@hey-api/typescript` will include comments in the generated code based on descriptions from your OpenAPI specification. If you want to reduce the size of your generated files or prefer cleaner output, you can disable comments.

* enabled

  openapi-ts.config.ts

  ```js
  export default {
    input: 'hey-api/backend', // sign up at app.heyapi.dev
    output: 'src/client',
    plugins: [
      // ...other plugins
      {
        comments: true, // default
        name: '@hey-api/typescript',
      },
    ],
  };
  ```

* disabled

  openapi-ts.config.ts

  ```js
  export default {
    input: 'hey-api/backend', // sign up at app.heyapi.dev
    output: 'src/client',
    plugins: [
      // ...other plugins
      {
        comments: false,
        name: '@hey-api/typescript',
      },
    ],
  };
  ```

## Resolvers

[Section titled “Resolvers”](#resolvers)

You can further customize this plugin’s behavior using [resolvers](https://heyapi.dev/openapi-ts/plugins/concepts/resolvers).

## API

[Section titled “API”](#api)

You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/typescript/types.ts) interface.

## Examples

You can view live examples on [StackBlitz](https://stackblitz.com/orgs/github/hey-api/collections/openapi-ts-examples) or on [GitHub](https://github.com/hey-api/openapi-ts/tree/main/examples).
