typescript/triple-slash-reference Correctness
What it does
Disallow certain triple slash directives in favor of ES module import declarations.
Why is this bad?
Use of triple-slash reference type directives is generally discouraged in favor of ECMAScript Module imports.
Examples
Examples of incorrect code for this rule:
/// <reference lib="code" />
globalThis.value;Configuration
This rule accepts a configuration object with the following properties:
lib
type: "always" | "never"
default: "always"
What to enforce for /// <reference lib="..." /> references.
"always"
Allow triple-slash lib references.
"never"
Disallow triple-slash lib references.
path
type: "always" | "never"
default: "never"
What to enforce for /// <reference path="..." /> references.
"always"
Allow triple-slash path references.
"never"
Disallow triple-slash path references.
types
type: "always" | "never" | "prefer-import"
default: "prefer-import"
What to enforce for /// <reference types="..." /> references.
"always"
Allow triple-slash types references.
"never"
Disallow triple-slash types references.
"prefer-import"
Prefer ES module import declarations over triple-slash types references. This option only reports when there is an existing import declaration for the same module.
For example, this would be reported as a lint violation with prefer-import:
/// <reference types="foo" />
import { bar } from "foo";How to use
To enable this rule in the CLI or using the config file, you can use:
oxlint --deny typescript/triple-slash-reference{
"rules": {
"typescript/triple-slash-reference": "error"
}
}