Rules

force-ts-extension

Require extensions and normalize them in ts or js mode.

Purpose and behavior

Require extensions and normalize them in ts or js mode.

The rule reports missing extensions without a fix. It normalizes extensions in ts/js mode like consistent-import-extension, including .mjs/.mts and .cjs/.cts. It checks relative paths and # aliases containing a slash in static imports, re-exports and literal dynamic imports. Slashless aliases such as #utils are outside its scope. Use require-import-extension plus consistent-import-extension instead. Presets omit this compatibility rule to avoid duplicate reports.

Options

{ mode: "ts" } is the default. Set { mode: "js" } for JavaScript, as with consistent-import-extension. These examples use ts mode. Check runtime module resolution before applying fixes.

Invalid example

import { foo } from './foo.js'

Valid example

import { foo } from './foo.ts'

Fixes and exceptions

This rule provides automatic fixes. Review each fix before applying it.

For a boundary exception, use oxlint-disable-next-line rules/force-ts-extension -- reason. Examples cover this rule only and may omit imports or declarations.

Source and tests

Opt-in compatibility rule. Both presets omit it because its import convention conflicts with their policy or its reports duplicate other rules.

force-ts-extension.ts · Tests