Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 23, 2025

Enums were being exported as type-only from the main index.ts file, making the enum objects unusable as values and causing TypeScript error TS1362.

The Problem

In version 0.84, when enums were enabled, the generated index.ts file used:

export type * from './types.gen';

This caused enum objects to be exported as types only, making them unusable as values:

import { MyEnum } from 'client';
console.log(MyEnum.VALUE); // ❌ TS1362: cannot be used as a value because it was exported using 'export type'

The Solution

The fix prevents enums from being incorrectly tagged as meta.kind = 'type' during symbol registration. Instead of complex binding logic changes, the solution addresses the root cause directly:

In handleComponent function: All enum modes are no longer tagged as 'type', allowing them to be exported as values:

// Don't tag enums as 'type' since they export runtime artifacts (values)
const isEnum = schema.type === 'enum' && plugin.config.enums.enabled;

const symbol = plugin.registerSymbol({
  exported: true,
  meta: {
    kind: isEnum ? undefined : 'type',
  },
  // ...
});

The Result

All enum modes now work correctly as both values and types:

// index.ts - All enum modes
export * from './types.gen'; // ✅ Allows both value and type imports

// index.ts - Non-enum types  
export type * from './types.gen'; // ✅ Type-only (unchanged)

// Usage now works for all enum modes
import { MyEnum } from 'client';
console.log(MyEnum.VALUE); // ✅ Works as value
let type: MyEnum = 'value'; // ✅ Works as type

This ensures that all enum modes can be used as values:

  • javascript: export const MyEnum = { ... } as const
  • typescript: export enum MyEnum { ... }
  • typescript-const: export const enum MyEnum { ... }

The fix is simple and surgical, addressing the root cause rather than working around symptoms. All existing functionality for regular types and other exports remains unchanged.

Fixes #2679.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link

vercel bot commented Sep 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hey-api-docs Ready Ready Preview Comment Sep 23, 2025 10:04am

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

changeset-bot bot commented Sep 23, 2025

🦋 Changeset detected

Latest commit: 3176525

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mrlubos
Copy link
Member

mrlubos commented Sep 23, 2025

@copilot The issue should be that we incorrectly tag the runtime enums as meta.kind = 'type'. Removing that line should be enough to fix the issue

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Broken Enums export on 0.84 Fix broken JavaScript enum exports in index.ts Sep 23, 2025
@Copilot Copilot AI requested a review from mrlubos September 23, 2025 08:38
Copilot finished work on behalf of mrlubos September 23, 2025 08:38
Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 23, 2025

@copilot The issue should be that we incorrectly tag the runtime enums as meta.kind = 'type'. Removing that line should be enough to fix the issue

You're absolutely right! The simpler approach is much better. I've simplified the fix to avoid tagging JavaScript enums as meta.kind = 'type' in the first place rather than modifying the binding logic.

The fix now checks for JavaScript enums in handleComponent and sets kind: undefined instead of kind: 'type'. This addresses the root cause directly and is much cleaner.

Commit: 42eb018

@mrlubos
Copy link
Member

mrlubos commented Sep 23, 2025

@copilot I think we simply want to check if it's any kind of enum, as the other enum modes are also runtime artifacts. So checking if enums are enabled should be all that's needed. Do you agree?

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 23, 2025

@copilot I think we simply want to check if it's any kind of enum, as the other enum modes are also runtime artifacts. So checking if enums are enabled should be all that's needed. Do you agree?

Absolutely! You're correct that all enum modes create runtime artifacts:

  • javascript: export const MyEnum = { ... } as const - runtime object
  • typescript: export enum MyEnum { ... } - runtime object
  • typescript-const: export const enum MyEnum { ... } - inlined but still runtime artifacts

I've updated the fix to check for any enum when enums are enabled: schema.type === 'enum' && plugin.config.enums.enabled. This ensures all enum modes can be used as values, not just JavaScript enums.

Commit: 72e5295

@Copilot Copilot AI changed the title Fix broken JavaScript enum exports in index.ts Fix broken enum exports in index.ts Sep 23, 2025
Copilot finished work on behalf of mrlubos September 23, 2025 09:03
@mrlubos mrlubos marked this pull request as ready for review September 23, 2025 09:31
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 23, 2025
@dosubot dosubot bot added bug 🔥 Something isn't working client Client package related labels Sep 23, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 23, 2025
Copy link

pkg-pr-new bot commented Sep 23, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@2680
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2680
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2680
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2680

commit: 3176525

Copy link

codecov bot commented Sep 23, 2025

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.26%. Comparing base (74ee594) to head (3176525).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...enapi-ts/src/plugins/@hey-api/typescript/plugin.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2680      +/-   ##
==========================================
- Coverage   25.26%   25.26%   -0.01%     
==========================================
  Files         385      385              
  Lines       37085    37086       +1     
  Branches     1781     1781              
==========================================
  Hits         9369     9369              
- Misses      27703    27704       +1     
  Partials       13       13              
Flag Coverage Δ
unittests 25.26% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mrlubos mrlubos merged commit 6476ecb into main Sep 23, 2025
16 of 17 checks passed
@mrlubos mrlubos deleted the copilot/fix-2679 branch September 23, 2025 10:14
@hey-api hey-api bot mentioned this pull request Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working client Client package related lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken Enums export on 0.84
2 participants