Skip to content

Cannot export self module as default #38387

Closed
@Fenzland

Description

@Fenzland

TypeScript Version: 3.8.3

Search Terms:
module import export circular

Background
I use to write module like this:

// module.js
export { foo, bar, baz, };
export * as default from './module.js'; // path of current file itself.

Then we can import the module with both to ways:

import { foo, } from './module.js';
import Module from './module.js';

Module.foo === foo; // true

That's work fine with JavaScript but not TypeScript.

Code

// module.ts
export * as default './module.ts';

Expected behavior: works like JavaScript.

Actual behavior:

error TS1359: Identifier expected. 'default' is a reserved word that cannot be used here.
export * as default from './module.ts';
            ~~~~~~~

So I modify my code to:

// module.ts
import * as Module './module.ts';
export default Module;

This works fine with JavaScript too, but not TypeScript again.

Expected behavior: works like JavaScript.

Actual behavior:

error TS2303: Circular definition of import alias 'Module'.
import * as Module from './test.ts';
       ~~~~~~~~~~~

I modify my code again to:

// module.ts
import * as Module './module.ts';
export default (Module);

It finally works, both JavaScript and TypeScript.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions