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

unicorn/prefer-export-from breaks type exports in typescript projects using the isolatedModules flag. #1727

Closed
nrgnrg opened this issue Feb 10, 2022 · 3 comments · Fixed by #1728

Comments

@nrgnrg
Copy link
Contributor

nrgnrg commented Feb 10, 2022

When autofixing exports in ts projects unicorn/prefer-export-from will change this:

import UIAvatar, {
  UIAvatarProps,
} from "./UIAvatar";

export type { UIAvatarProps };
export default UIAvatar;

into

export { default, UIAvatarProps } from "./UIAvatar";

Which results in a typescript error Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.ts(1205)

The correct fix should be:

export { default, type UIAvatarProps } from "./UIAvatar";

Type only exports should be prefixed with type.

I've also seen this problem happen the other way around before where a non type export gets bundled into an export type { ... } from "" and has broken internal library code as the autofix is applied using commit hooks.

@fisker
Copy link
Collaborator

fisker commented Feb 10, 2022

PR welcome.

@fisker
Copy link
Collaborator

fisker commented Feb 10, 2022

We need add something like kind: 'value' | 'type' to

function getImported(variable, sourceCode) {
and
function getExported(identifier, context, sourceCode) {

@nrgnrg
Copy link
Contributor Author

nrgnrg commented Feb 10, 2022

Hey @fisker, I wasn't too sure how to approach this but after having a quick poke around I think I've found a rather simple solution.

Have raised a PR, let me know how it looks to you #1728

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants