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
prefer-export-from
: Fix TypeScript compatibility
#1728
prefer-export-from
: Fix TypeScript compatibility
#1728
Conversation
670afc3
to
7d16cc0
Compare
I'm sorry to say this is not correct solution, those "imported" can also variables. I don't use ts myself, but afaik, Example: import { foo } from "foo";
export {foo};
export type {bar } from "foo"; The export can't be reused, need insert another export. |
Normally I don't dig deep for the ts parser, we can also simply skip the fix if you see any |
I'm not sure I follow exactly. Given your example the correct fix would be either: export { foo, type bar } from "foo"; or export { foo } from "foo";
export type { bar } from "foo"; Which this fix correctly substitutes, I've run this change with |
What's the result for the code I posted? (example updated) |
Ah ok I gotcha, it's reusing the |
This is perhaps not the most perfect solution because we could be smarter about it, but by just ignoring export declarations which are |
Your example now auto fix's to this: export type { bar } from "foo";
export { foo } from "foo"; |
99cb224
to
8e6ce4a
Compare
This will need a test. |
5eaf934
to
1f24e32
Compare
I've corrected the test failures and added a test for the change. |
I think I've addressed you comments, I now see the following output for the given inputs (before and after this change). Previously: value exports converted to type exports breaking code, or vice versa // input
import { foo } from "foo";
export { foo };
export type { bar } from "foo";
// Existing Transform:
export type { bar, foo } from "foo";
// Updated Transform:
export type { bar } from "foo";
export { foo } from "foo"; // input
import { foo } from "foo";
export { foo };
export { type bar } from "foo";
// Existing Transform:
export { type bar, foo } from "foo";
// Updated Transform:
export { type bar, foo } from "foo"; // input
import foo, { bar } from "foo";
export type { bar };
export default foo;
// Existing Transform:
export type { bar, default } from "foo";
// Updated Transform:
export type { bar } from "foo";
export { default } from "foo"; // input
import { foo } from 'foo';
export { foo };
export type { bar } from "foo";
export { baz } from "foo";
// Existing Transform:
export type { bar, foo } from "foo";
export { baz } from "foo";
// Updated Transform:
export type { bar } from "foo";
export { baz, foo } from "foo"; // input
import { foo } from 'foo';
export { foo };
export { type bar } from "foo";
export { baz } from "foo";
// Existing Transform:
export { type bar, foo } from "foo";
export { baz } from "foo";
// Updated Transform:
export { type bar, foo } from "foo";
export { baz } from "foo"; |
prefer-export-from
do not convert type exports to value exportsprefer-export-from
do not convert exportKind type
to value
or value
to type
when applying fix
prefer-export-from
do not convert exportKind type
to value
or value
to type
when applying fixprefer-export-from
preserve exportKind
when applying fix
Always add tests when you do logic change. |
@fisker the additional test cases have been added now |
f5740ab
to
72f0ad9
Compare
I'm working to make some improvements. |
import type {foo} from 'foo';
export type bar = foo; This seems not handled by our rule, if you are interested, maybe you can try to fix this in a separate PR? |
Your changes look good to me 👍 The inline type import/export syntax ( The responsibility of enforcing one style over the other does not feel like the responsibility of this rule, there is a tracking issue in |
Thanks for the information, I guess I was wrong, can you change it to prefer value export first? It should be simple. |
Inline type syntax? yeah I'll try and find the time this week to update that. Thanks for your work helping on this |
@fisker let me know how this looks |
Actually, I mean 3020b59, if @sindresorhus What's your opinion on this import {type foo} from 'foo';
export {type foo}
export type {bar} from 'foo';
export {baz} from 'foo'; FIX 1: export type {bar, foo} from 'foo'; // Reuse this type export.
export {baz} from 'foo'; FIX 2: export type {bar} from 'foo';
export {baz, type foo} from 'foo'; // Reuse this value export. |
I would go with fix 1. That's what most people would want, I think. |
Okay, I'll revert. |
However, my preference would be: export {baz, type foo, type bar} from 'foo'; Since it makes it possible to have a single statement. I think there should be a TODO comment to switch to that when the TS version with it is more widespread. |
This reverts commit 3020b59.
@nrgnrg already mentioned this in #1728 (comment), that should be handled in a separate rule. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with those changes, thanks for working on this, good job @nrgnrg .
prefer-export-from
preserve exportKind
when applying fixprefer-export-from
: Fix TypeScript compatibility
closes #1727
When applying a fix checks the
exportKind
and addstype
as a prefix to the specifier if it's a type export.