-
Notifications
You must be signed in to change notification settings - Fork 13.3k
export * as default in declaration file loses membersΒ #55829
Description
π Search Terms
Reexport, re-export, default, namespace, missing type
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about modules
β― Playground Link
π» Code
// @module: esnext
// @moduleResolution: bundler
// @filename: three.d.ts
export type Named = 0;
// @filename: two.d.ts
// ^^
// WORKAROUND2: Remove the '.d' and the error goes away
export type * as default from "./three";
// @filename: one.ts
import type ns from "./two";
type Alias = ns.Named; // <- error ts(2694)π Actual behavior
ERROR 2694: Namespace '"/two"' has no exported member 'Named'. The namespace is empty.
π Expected behavior
The exported type Named should be retained in the re-exported namespace.
Additional information about the issue
The issue is not specific to using type-only re-exports. export * as default also exhibits the problem.
The error goes away if we make any of the following changes/workarounds.
1. Re-export via a non-default name
The problem only occurs when using a default export to expose the namespace.
- Fails:
export type * as default from "./three"; - Succeeds:
export type * as foo from "./three";
2. Manually re-export
Desugaring the re-export fixes the problem.
- Fails:
export type * as default from "./three"; - Succeeds:
import type * as NS from "./three"; export type {NS as default}
3. Re-export in a regular *.ts file
The problem only exists when the re-export is in a *.d.ts file.
// @filename: two.ts <-- this works fine!
export type * as default from "./three";(We discovered the problem when performing post-build type-checking on the emitted declaration files.)
4. Using a different "moduleResolution" option
Not in the workbench, but when recreating in a local project the issue did not occur when moduleResolution was defaulting to 'classic'