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.
Installation
Section titled “Installation”In your configuration, add @hey-api/typescript to your plugins and you’ll be ready to generate TypeScript artifacts. 🎉
export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins '@hey-api/typescript', ],};Output
Section titled “Output”The TypeScript plugin will generate the following artifacts, depending on the input specification.
Requests
Section titled “Requests”A single request type is generated for each endpoint. It may contain a request body, parameters, and headers.
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”A single type is generated for all endpoint’s responses.
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”A type is generated for every reusable definition from your input.
export type Pet = { id?: number; name: string;};You can customize the naming and casing pattern for definitions types using the .name and .case options.
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.
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', }, ],};export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins { enums: 'javascript', name: '@hey-api/typescript', }, ],};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 are not a type-level extension of JavaScript and pose typing challenges.
Comments
Section titled “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.
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', }, ],};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”You can further customize this plugin’s behavior using resolvers.
You can view the complete list of options in the UserConfig interface.
Examples
You can view live examples on StackBlitz or on GitHub.