Skip to content
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

Cannot export a value if re-exporting a type with same name #42633

Closed
paul-marechal opened this issue Feb 4, 2021 · 3 comments
Closed

Cannot export a value if re-exporting a type with same name #42633

paul-marechal opened this issue Feb 4, 2021 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@paul-marechal
Copy link

Bug Report

TypeScript usually allows exporting values and types with the same name.

// a.ts
export const a = 1
export type a = string

But it doesn't work when re-exporting a type from a third-party library and exporting an arbitrary value at the same time.

// b.ts
export const a = 1
export type { a } from './a'  

🔎 Search Terms

export type re-export error

🕗 Version & Regression Information

  • Bug present in 4.1.3
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about re-export

⏯ Playground Link

https://codesandbox.io/s/misty-field-16f9f?file=/src/index.ts

💻 Code

export type { A } from "./a";
export const A = Symbol("A");

🙁 Actual behavior

Error:

Cannot redeclare exported variable 'A'. ts(2323)

🙂 Expected behavior

I would expect this to work since the re-exported name is purely a type.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Feb 4, 2021

I think this is working as intended. Import/export aliases can't merge with local declarations in TypeScript. What's more, export type doesn't strictly import the type side of things, it only restricts the things you can do with that import to type-like positions, so even if we wanted to ease the restriction just for export type, we still couldn't.

See

@DanielRosenwasser DanielRosenwasser added the Working as Intended The behavior described is the intended behavior; this is not a bug label Feb 4, 2021
@paul-marechal
Copy link
Author

paul-marechal commented Feb 4, 2021

Import/export aliases can't merge with local declarations in TypeScript.

Should this limitation on merging behavior be documented in the appropriate section of the official documentation?

@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

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