Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

After v0.86, the TypeScript declaration bundler renames the class-level type parameter T to T$1, causing method-level type parameters also named T to incorrectly reference the class type parameter instead of their own scope.

// Before: method type parameter incorrectly resolves to class T$1
forEach<T extends IrTopLevelKind>(...args: [
  ...events: ReadonlyArray<T$1>,  // Wrong - should be method T
  callback: (event: WalkEvent<T$1>) => void
]): void;

// After: distinct parameter name preserves method scope
forEach<TKind extends IrTopLevelKind>(...args: [
  ...events: ReadonlyArray<TKind>,
  callback: (event: WalkEvent<TKind>) => void
]): void;

Changes

  • Renamed method type parameters to avoid shadowing:
    • forEach: TTKind
    • getPlugin, getPluginOrThrow: TTName

Impact

Users can now use forEach without type errors:

plugin.forEach('schema', 'operation', (event) => {
  // event is now correctly typed as WalkEvent<'schema' | 'operation'>
  // instead of 'never'
});
Original prompt

This section details on the original issue you should resolve

<issue_title>PluginInstance.forEach is typed incorrectly after v0.86</issue_title>
<issue_description>### Description

After v0.86, PluginInstance.forEach is typed incorrectly. This is what the generated type before:

forEach<T extends IrTopLevelKind = IrTopLevelKind>(...args: [...events: ReadonlyArray<T>, callback: (event: WalkEvent<T>) => void]): 

and this is what we have now (note the T$1):

forEach<T extends IrTopLevelKind = IrTopLevelKind>(...args: [...events: ReadonlyArray<T$1>, callback: (event: WalkEvent<T$1>) => void]): 

Reproducible example or configuration

You can find the live minimal example here.

import type { DefinePlugin } from '@hey-api/openapi-ts';

type MyPluginConfig = { readonly name: 'myplugin' };
type MyConfig = DefinePlugin<MyPluginConfig>;

export const handler: MyConfig['Handler'] = ({ plugin }) => {
  plugin.forEach('schema', 'operation', (event) => {
    console.log(event);
  });
};

will produce the type checking error:

No overload matches this call.
  Argument of type '[string, string, (event: never) => void]' is not assignable to parameter of type '[...events: Types<MyPluginConfig, MyPluginConfig, never>[], callback: (event: never) => void]'.
    Type at positions 0 through 1 in source is not compatible with type at position 0 in target.
      Type 'string' is not assignable to type 'Types<MyPluginConfig, MyPluginConfig, never>'.
        Type 'string' is not assignable to type '{ config: MyPluginConfig; resolvedConfig: MyPluginConfig; }'.
  Argument of type '[string, string, (event: never) => void]' is not assignable to parameter of type '[...events: Types<MyPluginConfig, MyPluginConfig, never>[], callback: (event: never) => void, options: WalkOptions<Types<MyPluginConfig, MyPluginConfig, never>>]'.
    Type at position 0 in source is not compatible with type at position 0 in target.
      Type 'string' is not assignable to type 'Types<MyPluginConfig, MyPluginConfig, never>'.(2769)

OpenAPI specification (optional)

No response

System information (optional)

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@bolt-new-by-stackblitz
Copy link

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

@changeset-bot
Copy link

changeset-bot bot commented Oct 31, 2025

🦋 Changeset detected

Latest commit: a625980

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

@vercel
Copy link

vercel bot commented Oct 31, 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 Oct 31, 2025 2:32am

…r conflicts

Renamed method-level type parameters to avoid conflicts with class-level type parameter:
- forEach: T -> TKind
- getPlugin: T -> TName
- getPluginOrThrow: T -> TName

This fixes the issue where the bundler was incorrectly resolving method-level type parameters to the class-level T$1 instead of keeping them separate.

Co-authored-by: mrlubos <[email protected]>
Copilot AI changed the title [WIP] Fix PluginInstance.forEach typing issue after v0.86 Fix: Type parameter shadowing in PluginInstance methods after bundling Oct 31, 2025
Copilot finished work on behalf of mrlubos October 31, 2025 01:18
Copilot AI requested a review from mrlubos October 31, 2025 01:18
@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 30.89%. Comparing base (cec4739) to head (a625980).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...es/openapi-ts/src/plugins/shared/utils/instance.ts 69.23% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2897   +/-   ##
=======================================
  Coverage   30.89%   30.89%           
=======================================
  Files         488      488           
  Lines       40458    40458           
  Branches     2523     2523           
=======================================
  Hits        12501    12501           
  Misses      27922    27922           
  Partials       35       35           
Flag Coverage Δ
unittests 30.89% <69.23%> (ø)

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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 31, 2025

Open in StackBlitz

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

commit: a625980

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 31, 2025
@mrlubos mrlubos marked this pull request as ready for review October 31, 2025 02:32
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug 🔥 Something isn't working labels Oct 31, 2025
@mrlubos mrlubos merged commit 505b92b into main Oct 31, 2025
17 checks passed
@mrlubos mrlubos deleted the copilot/fix-plugininstance-foreach-typing branch October 31, 2025 02:40
@hey-api hey-api bot mentioned this pull request Oct 31, 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 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.

PluginInstance.forEach is typed incorrectly after v0.86

2 participants