feat(typescript): Update type import specifier rules #381
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ref: https://github.com/MetaMask/ocap-kernel/pull/175
This replaces
@typescript-eslint/consistent-type-imports
withimport-x/consistent-type-specifier-style
, and an exhortation to enableverbatimModuleSyntax
(requires TypeScript >=5) in the tsconfigs of our packages.Heretofore, we have enforced the existence of type import specifiers, but not that they are stylistically consistent. The options are:
import type { a } from 'x'}
import { type a } from 'x'}
The rule
@typescript-eslint/consistent-type-imports
has been responsible for this. This rule has an option namedfixTypes
, but that only applies when a type-only import is not specified as a type-only import. In other words, it enforces the existence of type import specifiers, but not that they're stylistically consistent.Rather than using
@typescript-eslint/consistent-type-imports
and its confusingly named options, we are better off enablingverbatimModuleSyntax
in ourtsconfig
files, and enablingimport-x/consistent-type-specifier-style
. In this way, the existence of type import specifiers is enforced bytsc
, and theimport-x
ESLint plugins ensures that they are consistent. We use the "top-level" style because that results inimport type { a } from 'x';
being elided completely from the JS output as opposed toimport { type a } from 'x';
which would be emitted asimport {} from 'x';
. I don't know if that's actually harmful, but it seems surprising, and I don't like surprises.Supporting documentation:
@typescript-eslint/consistent-type-imports
rule documentationverbatimModuleSyntax
docs