Conversation
📝 WalkthroughWalkthroughThe TypeScript definition file Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/defu.d.cts`:
- Around line 13-14: Remove the top-level `export type { Defu, DefuFn,
DefuInstance }` and replace it by declaring a namespace named `defuProxy` that
re-exports the types (`Defu`, `DefuFn`, `DefuInstance`) inside it, then use
`export = defuProxy` as the module export; locate the current `export type`
statement and the `defuProxy`/`defu` declarations and move the type definitions
into `declare namespace defuProxy { export type Defu = ...; export type DefuFn =
...; export type DefuInstance = ... }` so the module uses the
CommonJS-compatible `export = defuProxy` mechanism.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
|
|
||
| export type { Defu, DefuFn, DefuInstance } |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In the TypeScript version used by this project, is export = fooallowed in the same.d.ctsfile asexport type { A, B }? If not, what is the recommended pattern to expose additional types from a CommonJS declaration module?
💡 Result:
No, export = foo is not allowed in the same .d.cts file as export type { A, B }. .d.cts files are treated as CommonJS declaration modules, where the primary export must use the CommonJS-style export = syntax for the module.exports value, and ES module-style named exports like export type are incompatible in the same file because they represent different module systems. The recommended pattern to expose additional types from a CommonJS declaration module (including .d.cts) is to declare them within a namespace attached to the main exported value, or use top-level ES module-style export type only if not mixing with export =. For export = foo specifically: declare type A = ...; declare type B = ...; declare const foo: FooType & { A: A; B: B }; // or namespace export = foo; Or more commonly for functions/classes with properties: declare function foo: void; declare namespace foo { export type A = ...; export type B = ...; } export = foo; This mirrors official patterns from TypeScript documentation for CommonJS modules. For Node16/nodenext with .d.cts, the same CommonJS declaration rules apply as .d.ts for require conditions, using export = for the exports object and namespaces for additional members/types.
Citations:
- 1: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html
- 2: https://typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html
- 3: Types in
d.ctsis incorrect when the entry has multiple exports unbuild#531 - 4: should allow use
export =in.ctswhen module is esnext microsoft/TypeScript#51018 - 5: https://zenn.dev/uhyo/articles/typescript-module-option?locale=en
Remove export type statement; incompatible with export = in CommonJS declaration files
In .d.cts files, export = defuProxy and export type { ... } cannot coexist. TypeScript treats .d.cts as CommonJS declaration modules where export = is the sole export mechanism. Expose these types via a namespace instead:
declare namespace defuProxy {
export type Defu = ...
export type DefuFn = ...
export type DefuInstance = ...
}
export = defuProxy
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@lib/defu.d.cts` around lines 13 - 14, Remove the top-level `export type {
Defu, DefuFn, DefuInstance }` and replace it by declaring a namespace named
`defuProxy` that re-exports the types (`Defu`, `DefuFn`, `DefuInstance`) inside
it, then use `export = defuProxy` as the module export; locate the current
`export type` statement and the `defuProxy`/`defu` declarations and move the
type definitions into `declare namespace defuProxy { export type Defu = ...;
export type DefuFn = ...; export type DefuInstance = ... }` so the module uses
the CommonJS-compatible `export = defuProxy` mechanism.
407b516#r181346453