-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Proposal for new rule - consistent style for type-only exports #3597
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
Comments
I'll leave this open, as it is a code style lint rule, but IMO it's pretty low value (see below). If someone wants to work on it - they can feel free to. I definitely get the motivation - but I don't think this really makes much of a difference in code.
Deeper explanationimport { T } from 'module';
const x: T = 'foo'; if the build tool notices OTOH, This rule would just be a coding style thing. Exports for types declared in the same file can be statically verified by build tools to be deletable. All other exports are either values or require type information to understand. Deeper explanationtype T = string;
export { T }; Single-file static analysis tells us
|
webpack balks at type-only exports when used with babel: |
This rule would be great to force type-only re-exports indeed. You can find an example in this issue from Storybook storybookjs/storybook#13504 |
Useful for |
I could get over this problem by enabling |
edit I thought that I was wrong. |
I don't think that is the case anymore, by reading their docs https://www.typescriptlang.org/tsconfig#isolatedModules
I can confirm that type-checks happen as expected on my local projects. |
I would greatly appreciate this rule. I had considered Would a PR be welcome? Or is there someone working on this? For background, the particular scenario that we hit looks like this: A library exports a type from another library:
A tool like esbuild is used to transpile the TypeScript and produce an ESM bundle of the library to be consumed by a browser, externalizing all dependencies (which will be resolved with import maps.) Because the export is not explicitly a type, and esbuild doesn't know the types of If the type export is explicit about it being a type, esbuild can drop the export safely and the bundle becomes browser consumable. |
We are a community run project. The volunteer maintainers spend most of their time triaging issues and reviewing PRs. This means that most issues will not progress unless a member of the community steps up and champions it. If this issue is important to you - consider being that champion. |
Cool beans. I'll get a PR going. |
This is now in PR. Also I just realized Andrew merged this in: Which allows for type annotations inside brackets next to specifiers: import { Button, type ButtonProps } from '...';
export { Button, type ButtonProps } from '...'; So this might be addressed in a future PR to add an option to |
Thanks @dzearing for looking at this. Also worth noting that enabling this rule may have positive perf implications for ts-loader/webpack usage as well |
Basically this is the export version of this proposal which has now been implemented:
#2200
Proposal
This is useful for having alongside
import/exports-last
rule: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/exports-last.mdThe text was updated successfully, but these errors were encountered: