Skip to content

TCS-10: Enforce import type via consistent-type-imports#67

Open
brettcutt-aligent wants to merge 1 commit into
mainfrom
feature/TCS-10_add-type-import-as-eslint-rule
Open

TCS-10: Enforce import type via consistent-type-imports#67
brettcutt-aligent wants to merge 1 commit into
mainfrom
feature/TCS-10_add-type-import-as-eslint-rule

Conversation

@brettcutt-aligent
Copy link
Copy Markdown
Contributor

Description of the proposed changes
Enforce import type for type-only imports across consuming projects by adding @typescript-eslint/consistent-type-imports to the shared base ESLint config.

  • Type-only imports were previously written as regular imports → now flagged as errors and auto-fixed to import type { ... }.

    // Before
    import { Cart } from './types';
    let cart: Cart;
    
    // After
    import type { Cart } from './types';
    let cart: Cart;
  • Mixed runtime/type imports were previously a single statement → now split into separate runtime and import type statements (fixStyle: 'separate-type-imports').

    // Before
    import { createCart, Cart } from './cart';
    const c: Cart = createCart();
    
    // After
    import { createCart } from './cart';
    import type { Cart } from './cart';
    const c: Cart = createCart();
  • Inline import('...').Foo type annotations were previously permitted → now disallowed (disallowTypeAnnotations: true).

    // Before
    let handler: import('./types').Handler;
    function render(c: import('react').FC<Props>) {}
    
    // After
    import type { FC } from 'react';
    import type { Handler } from './types';
    let handler: Handler;
    function render(c: FC<Props>) {}
  • The rule lives in its own config object scoped to **/*.{ts,tsx,js,jsx,mjs,cjs} so it doesn't load against non-JS/TS files (e.g. GraphQL virtual documents extracted by @graphql-eslint/parser), which lack the TS parser services this rule requires.

Screenshots (if applicable)
Symlinked and tested on take-flight repo
image

Other solutions considered (if any)

Notes to PR author

⚠️ Please make sure the changes adhere to the guidelines mentioned in our contribution guide.

Notes to reviewers

ℹ️ When you've finished leaving feedback, please add a final comment to the PR tagging the author, letting them know that you have finished leaving feedback

Add @typescript-eslint/consistent-type-imports as an error in the base config so type-only imports are written with import type and any mixed runtime/type imports are split (fixStyle: 'separate-type-imports'). Inline import('...').Foo type annotations are disallowed.

The rule is placed in its own config object scoped to **/*.{ts,tsx,js,jsx,mjs,cjs} so it doesn't load for non-JS/TS files (e.g. GraphQL virtual documents extracted by @graphql-eslint/parser), which lack the parser services this rule requires.
@brettcutt-aligent brettcutt-aligent marked this pull request as ready for review May 21, 2026 23:41
@brettcutt-aligent brettcutt-aligent requested review from a team as code owners May 21, 2026 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant