Skip to content

export * as default in declaration file loses membersΒ #55829

@acutmore

Description

@acutmore

πŸ”Ž 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

https://www.typescriptlang.org/dev/bug-workbench/?moduleResolution=100&emitDeclarationOnly=true&ts=5.2.2#code/PTAEAEFsHsBMFcA2BTAXKZBnAdsgHgC4CwAUCBDAigEpbSLwECW026ARvNrCgE6mly4AGZMU2AIaQ0oAgAteyZADpYygplL4ADtF4FZAT23JQAOSnJYoALygADAG4BZMCLHJJ09AQDu0VXVNV1BQsPCI0AA9KMEwSITQxRgAN1N5UwByVUzQCW5ZOVNkXl49UABzaCw83wlDUC08XX1QACo8zFBYZGEJJANhMshQACJlYHlFZFHnEjiIUXFLdFYVDVImSBaDbC6h6BHxyf9Z0gJjUwBBRCYJLrs95QtpWEcw8gBRamoAeWpQAAmABsAE4ACzoF5YbQSADGWVGJ2go1ycnuoGw0AwzT0BCsoGkkHYJVAmWhsGyCzCUQA-EA

πŸ’» 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'

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions