Description
Bundling declarations for a barrel that gives explicit typeof annotations to namespace-imported exports produces references to nonexistent *2 namespace members.
For example, the generated declaration contains:
declare const makeModel2: typeof ModelModule.makeModel2;
declare const createSession2: typeof SessionModule.createSession2;
But the generated namespaces only export makeModel and createSession, so consumers fail to type-check.
This reproduces with @bunup/dts@0.14.53, which includes the namespace-import alias restoration fix.
Versions
- Bun:
1.3.13
- Bunup:
0.16.32
@bunup/dts: 0.14.53
- TypeScript:
7.0.2
- Platform: Linux x64
Minimal reproduction
package.json
{
"name": "bunup-dts-namespace-repro",
"private": true,
"type": "module",
"devDependencies": {
"bunup": "0.16.32",
"typescript": "7.0.2"
}
}
tsconfig.json
{
"compilerOptions": {
"declaration": true,
"isolatedDeclarations": true,
"module": "Preserve",
"moduleResolution": "bundler",
"target": "ESNext",
"strict": true
},
"include": ["src/**/*.ts"]
}
src/model.ts
export interface Model {
readonly name: string;
}
export const makeModel = (name: string): Model => ({ name });
src/session.ts
import type { Model } from "./model.js";
export interface Session {
readonly model: Model;
}
export const createSession = (model: Model): Session => ({ model });
src/index.ts
import * as ModelModule from "./model.js";
import * as SessionModule from "./session.js";
export const makeModel: typeof ModelModule.makeModel = ModelModule.makeModel;
export const createSession: typeof SessionModule.createSession = SessionModule.createSession;
export type { Model } from "./model.js";
export type { Session } from "./session.js";
consumer.ts
import { createSession, makeModel } from "./dist/index.js";
createSession(makeModel("demo"));
Commands
bun install
bunup src/index.ts --target bun
tsc --noEmit --module Preserve --moduleResolution bundler --target ESNext consumer.ts
Actual result
Bunup exits successfully, but the consumer type-check fails:
dist/index.d.ts(15,46): error TS2551: Property 'makeModel2' does not exist on type 'typeof ModelModule'. Did you mean 'makeModel'?
dist/index.d.ts(16,52): error TS2551: Property 'createSession2' does not exist on type 'typeof SessionModule'. Did you mean 'createSession'?
Generated dist/index.d.ts excerpt:
declare namespace ModelModule {
export { makeModel, Model };
}
declare namespace SessionModule {
export { createSession, Session };
}
declare const makeModel2: typeof ModelModule.makeModel2;
declare const createSession2: typeof SessionModule.createSession2;
export { makeModel2 as makeModel, createSession2 as createSession, Session, Model };
--dts.splitting produces the same invalid declaration. In the larger project where this was discovered, --dts.infer-types also produces the same invalid references.
Expected result
The generated declaration should reference the namespace's existing makeModel and createSession members, and the consumer should type-check successfully.
Workaround
Disable Bunup declaration bundling and let TypeScript emit modular declarations:
bunup src/index.ts --target bun --no-dts && tsc --emitDeclarationOnly --rootDir src --outDir dist
Description
Bundling declarations for a barrel that gives explicit
typeofannotations to namespace-imported exports produces references to nonexistent*2namespace members.For example, the generated declaration contains:
But the generated namespaces only export
makeModelandcreateSession, so consumers fail to type-check.This reproduces with
@bunup/dts@0.14.53, which includes the namespace-import alias restoration fix.Versions
1.3.130.16.32@bunup/dts:0.14.537.0.2Minimal reproduction
package.json{ "name": "bunup-dts-namespace-repro", "private": true, "type": "module", "devDependencies": { "bunup": "0.16.32", "typescript": "7.0.2" } }tsconfig.json{ "compilerOptions": { "declaration": true, "isolatedDeclarations": true, "module": "Preserve", "moduleResolution": "bundler", "target": "ESNext", "strict": true }, "include": ["src/**/*.ts"] }src/model.tssrc/session.tssrc/index.tsconsumer.tsCommands
Actual result
Bunup exits successfully, but the consumer type-check fails:
Generated
dist/index.d.tsexcerpt:--dts.splittingproduces the same invalid declaration. In the larger project where this was discovered,--dts.infer-typesalso produces the same invalid references.Expected result
The generated declaration should reference the namespace's existing
makeModelandcreateSessionmembers, and the consumer should type-check successfully.Workaround
Disable Bunup declaration bundling and let TypeScript emit modular declarations:
bunup src/index.ts --target bun --no-dts && tsc --emitDeclarationOnly --rootDir src --outDir dist