Skip to content

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

Merged
brettcutt-aligent merged 1 commit into
mainfrom
feature/TCS-10_add-type-import-as-eslint-rule
May 25, 2026
Merged

TCS-10: Enforce import type via consistent-type-imports#67
brettcutt-aligent merged 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
Copy link
Copy Markdown
Contributor

@kai-nguyen-aligent kai-nguyen-aligent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this, Brett ❤️

@nettree
Copy link
Copy Markdown
Contributor

nettree commented May 25, 2026

LGTM, let's go :)

@brettcutt-aligent brettcutt-aligent merged commit bcca6f3 into main May 25, 2026
2 checks passed
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.

3 participants