Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

napi/transform: ts declaration file - incorrect Es2015BindingOptions interface name #6254

Closed
marcalexiei opened this issue Oct 2, 2024 · 2 comments · Fixed by #6260
Closed
Labels
C-bug Category - Bug

Comments

@marcalexiei
Copy link

Es2015BindingOptions interface is declared here:

export interface Es2015BindingOptions {

however when used inside TransformOptions it has the wrong name: ES2015BindingOptions (the S is uppercased)

es2015?: ES2015BindingOptions

So when compiling with typescript using skipLibCheck: false this cause the following error:

node_modules/.pnpm/oxc-transform@0.30.5/node_modules/oxc-transform/index.d.ts:195:12 - error TS2552: Cannot find name 'ES2015BindingOptions'. Did you mean 'Es2015BindingOptions'?

195   es2015?: ES2015BindingOptions

I noticed that this file is generated using napi-rs:

/* auto-generated by NAPI-RS */

So I assume I can't simply fix the typo and send a PR 😅.
After a quick search in the source code I'm unable to find any reference for the incorrect name (Es2015BindingOptions) expect the one in the declaration file, I found only ES2015BindingOptions.

I'm not familiar with rust project so I can't provide additional information 😢.

@marcalexiei marcalexiei added the C-bug Category - Bug label Oct 2, 2024
@shulaoda
Copy link
Member

shulaoda commented Oct 2, 2024

In napi-rs, Rust struct and field names are handled differently when exported to TypeScript interfaces:

  1. Struct names: When a Rust struct name contains mixed case letters or numbers, napi-rs automatically converts it to camelCase. For example, ES2015BindingOptions becomes Es2015BindingOptions in TypeScript.

  2. Field type references: When referencing a struct type in another struct (such as in TransformOptions), the original struct name is preserved. So, es2015: Option<ES2015BindingOptions> retains the original ES2015BindingOptions name in TypeScript.

Let me understand the relevant knowledge and see if there is a better solution.

@marcalexiei
Copy link
Author

Hello shulaoda,
thanks for the detailed explanation and for opening the PR to fix the issue so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category - Bug
Projects
None yet
3 participants