The ESLint rule type-only-import/require-type-only-export
is provided by eslint-plugin-type-only-import
library.
This rule will trigger on any TypeScript export
statements with source string literal matching the given pattern, and the statement not being type
-only.
This kind of transformation is extremely useful when certain packages or source files are meant to only export
types, not resulting in runtime export
statements.
Assuming the plugin would be configured to add type
modifier to all imports/exports which have target string literal matching pattern *.types
, here are few examples about valid and invalid code
code | is valid | auto-fixed to |
---|---|---|
export * as code from "./code" |
☑️ | Target string literal does not match given pattern and thus the statement is unaffected. |
export * from "./code.types" |
❌ | export type * from "./code.types" |
export { X } from "./code.types" |
❌ | export type { X } from "./code.types" |
Please see the test file for more examples on valid and invalid code.
This rule accepts exactly one option value, which is an object with all properties being optional. See options file for JSON schema of the rule, and corresponding TS type.