diff --git a/examples/react/src/shims.ts b/examples/react/src/shims.ts new file mode 100644 index 0000000..9158f35 --- /dev/null +++ b/examples/react/src/shims.ts @@ -0,0 +1,9 @@ +declare module 'foo' { + import type { ReactDOM } from 'react' + + type Foo = { + bar: ReactDOM + } + + export = Foo +} diff --git a/examples/react/vite.config.ts b/examples/react/vite.config.ts index 9b42365..4df8591 100644 --- a/examples/react/vite.config.ts +++ b/examples/react/vite.config.ts @@ -29,7 +29,7 @@ export default defineConfig({ exclude: ['src/ignore'], // aliasesExclude: [/^@components/], staticImport: true, - rollupTypes: true, + // rollupTypes: true, insertTypesEntry: true }) ] diff --git a/src/transform.ts b/src/transform.ts index f9174c0..4efde4f 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -221,7 +221,17 @@ export function transformCode(options: { } if (ts.isModuleDeclaration(node)) { - declareModules.push(s.slice(node.pos, node.end + 1)) + if ( + node.body && + ts.isModuleBlock(node.body) && + !node.body.statements.some( + s => ts.isExportAssignment(s) || ts.isExportDeclaration(s) || ts.isImportDeclaration(s) + ) + ) { + declareModules.push(s.slice(node.pos, node.end + 1)) + } + + return false } })