Skip to content

Cannot export self module as default #38387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Fenzland opened this issue May 7, 2020 · 1 comment
Closed

Cannot export self module as default #38387

Fenzland opened this issue May 7, 2020 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@Fenzland
Copy link

Fenzland commented May 7, 2020

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.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 5, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone Jun 5, 2020
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Aug 31, 2020
@rbuckton
Copy link
Contributor

This was fixed by #39803 and shipped in TS 4.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

3 participants