Skip to content

"import type { X }" with exported value with same name gives "Individual declarations in merged declaration 'X' must be all exported or all local." #50880

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
mb21 opened this issue Sep 21, 2022 · 5 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@mb21
Copy link

mb21 commented Sep 21, 2022

Bug Report

🔎 Search Terms

  • Individual declarations in merged declaration 'X' must be all exported or all local.
  • import type

🕗 Version & Regression Information

  • This is the behavior in every version I tried, the latest being 4.8.3, and I reviewed the FAQ for entries.

⏯ Playground Link

cannot import other files in playground

💻 Code

import type { x } from './foo';

export const x = 7

🙁 Actual behavior

Running tsc gives:

Individual declarations in merged declaration 'x' must be all exported or all local.

🙂 Expected behavior

No error.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Sep 21, 2022
@RyanCavanaugh
Copy link
Member

The error is exactly describing the situation that's happening.

You can write

import type { x } from './foo';

const x = 7

export { x };

@mb21
Copy link
Author

mb21 commented Sep 22, 2022

Thanks, that works indeed!

I suppose I don't know enough about JavaScript module syntax to see the difference :P export { x } is not a declaration?

@mb21 mb21 closed this as completed Sep 22, 2022
@mb21
Copy link
Author

mb21 commented Sep 22, 2022

Actually, it doesn't work. There is no type error in the exporting file, but when I save what you posted to bar.ts, and in another file:

import { x } from './bar';
console.log(x);

I get:

'x' cannot be used as a value because it was imported using 'import type'

Default export seems to work, but that wouldn't be tree-shakable :-(

@mb21 mb21 reopened this Sep 22, 2022
@whzx5byb
Copy link

@mb21 See #40583 (comment)

@mb21
Copy link
Author

mb21 commented Sep 23, 2022

Thanks! This works indeed:

type x = import("./foo").x;
export const x = 7;

@mb21 mb21 closed this as completed Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants