Describe the bug
When you declare a TypeScript namespace, and export it by named export, it cannot be auto imported. However, export the namespace by default export works fine.
Not only that, it can also accidentally export variables and types that are inside the namespace, which cannot be accessed directly. This causes these auto imported variables to point to non-existent variables and cannot be used normally.
Example
Source code:
// src/utils/test.ts
export namespace NamedNS {
export const foo = "foo";
export type Foo = string;
}
namespace DefaultNS {
export const bar = "bar";
export type Bar = string;
}
export default DefaultNS;
Actual result dts file:
// auto-imports.d.ts
export {}
declare global {
const bar: typeof import('./src/utils/test')['bar']
const foo: typeof import('./src/utils/test')['foo']
const test: typeof import('./src/utils/test')['default']
}
// for type re-export
declare global {
export type { Foo, Bar } from './src/utils/test'
import('./src/utils/test')
}
Expected result dts file:
// auto-imports.d.ts
export {}
declare global {
const NamedNS: typeof import('./src/utils/test')['NamedNS']
const test: typeof import('./src/utils/test')['default']
}
// for type re-export
declare global {
export type { NamedNS, default as test } from './src/utils/test'
import('./src/utils/test')
}
Reproduction
https://stackblitz.com/edit/vitejs-vite-eyr3zatt?file=src%2Futils%2Ftest.ts,auto-imports.d.ts
System Info
System:
OS: Windows 11 10.0.26100
CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-12600KF
Memory: 16.77 GB / 31.82 GB
Binaries:
Node: 23.6.1 - D:\Program Files\nodejs\node.EXE
npm: 10.9.2 - D:\Program Files\nodejs\npm.CMD
pnpm: 10.14.0 - D:\pnpm\pnpm.CMD
Browsers:
Edge: Chromium (139.0.3405.119)
Internet Explorer: 11.0.26100.1882
Used Package Manager
pnpm
Validations
Describe the bug
When you declare a TypeScript namespace, and export it by named export, it cannot be auto imported. However, export the namespace by default export works fine.
Not only that, it can also accidentally export variables and types that are inside the namespace, which cannot be accessed directly. This causes these auto imported variables to point to non-existent variables and cannot be used normally.
Example
Source code:
Actual result dts file:
Expected result dts file:
Reproduction
https://stackblitz.com/edit/vitejs-vite-eyr3zatt?file=src%2Futils%2Ftest.ts,auto-imports.d.ts
System Info
System: OS: Windows 11 10.0.26100 CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-12600KF Memory: 16.77 GB / 31.82 GB Binaries: Node: 23.6.1 - D:\Program Files\nodejs\node.EXE npm: 10.9.2 - D:\Program Files\nodejs\npm.CMD pnpm: 10.14.0 - D:\pnpm\pnpm.CMD Browsers: Edge: Chromium (139.0.3405.119) Internet Explorer: 11.0.26100.1882Used Package Manager
pnpm
Validations