Comments (1)
Thought I'd share some learnings that may be helpful when you upgrade TypeScript and @typescript-eslint/eslint-plugin
(no rush 😉).
TypeScript has deprecated importsNotUsedAsValues
since v5. I initially thought the replacement for this was verbatimModuleSyntax
but turns out it's a bit more complex because importsNotUsedAsValues
was never meant to be used to enforce the import type ...
code style in the first place ... and neither is verbatimModuleSyntax
.
The recommendation from this article seems to be to remove importsNotUsedAsValues
and verbatimModuleSyntax
altogether from tsconfig.json
and to use ESLint rules instead.
Moreover, with inline type
qualifiers, the best practice for dealing with type imports seems to have changed a bit, in particular when it comes to duplicate imports. Here is what I think we should aim for:
- Enforce the use of
type
qualifiers for type-only imports:// Correct import { type Foo } from './utils' const foo: Foo = 1; // Incorrect import { Foo } from './utils' const foo: Foo = 1;
- Enforce the use of inline
type
qualifiers for type-only imports (note that statements that contain only inline type imports are correctly removed bytsc
whenverbatimModuleSyntax
is disabled):// Correct import { type Foo } from './utils' // Incorrect import type { Foo } from './utils'
- Never allow duplicate imports, even when types are involved, thanks again to inline
type
qualifiers:// Correct import { Bar, type Foo } from './utils' // Incorrect import { Bar } from './utils' import type { Foo } from './utils' // Incorrect import { Bar } from './utils' import { type Foo } from './utils'
From what I gather, this would be achieved with the following rules:
- @typescript-eslint/consistent-type-imports with
{ prefer: 'type-imports' }
(already enabled by Galex) to enforce requirement nb 1 - @typescript-eslint/consistent-type-imports with also
{ fixStyle: 'inline-type-imports' }
(not yet configured by Galex) to enforce requirement nb 2 - import/no-duplicates with
{ 'prefer-inline': true }
(currently disabled by Galex in TS projects) to enforce requirement nb 3
I think rule import/consistent-type-specifier-style, which is enabled by Galex with { 'prefer-inline': true }
, should then be disabled, as I think it does the same thing as { fixStyle: 'inline-type-imports' }
in @typescript-eslint/consistent-type-imports
.
from eslint-config-galex.
Related Issues (20)
- Consider eslint-plugin-css-modules
- Integrate the important parts of `@remix/eslint-config` HOT 1
- Dependency Dashboard
- evaluate eslint-plugin-etc HOT 1
- fix readme HOT 1
- fix no-unreadable-array-destructuring HOT 1
- TS error with `createConfig` HOT 6
- JS/TS project migration HOT 7
- `getDependencies` called twice HOT 2
- initial v5 plans HOT 3
- Support Next 13 HOT 13
- Could `import/order` be replaced with `simple-import-sort`? HOT 2
- Clarify reasons for disabling TS rules (and consider re-enabling some) HOT 1
- lodash.merge doesn't actually merge appropriately
- jest/unbound-method throws in CRA due to not being properly set up
- Slow rule
- [Prettier compat] format may return Promise
- [jest rules] unbound-method needs parserOptions.project set
- Consider `eslint-plugin-react-refresh`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-config-galex.