@typescript-eslint/triple-slash-reference
Disallow /// <reference /> comments where an import does the job
Also called typescript-eslint/triple-slash-reference, typescript/triple-slash-reference
/// <reference path="..." /> and /// <reference types="..." /> pull another file or a type package into the current file from a comment. A comment is easy to overlook, tools that follow imports don't see it, and it stays behind when the code that needed it is gone. Use an import instead.
By default path references are always reported, types references are reported if the file also imports the same module, and lib references are allowed.
This rule is on by default in TypeScript files.
Configure#
On by default as a warning. To turn it off:
[lint.rules]
"@typescript-eslint/triple-slash-reference" = "off" # or "error"Every option, set to its default:
[lint.rules]
"@typescript-eslint/triple-slash-reference" = ["warn", {
path = "never", # "always" or "never"
types = "prefer-import", # "always", "never" or "prefer-import"
lib = "always", # "always" or "never"
}]Examples#
/// <reference path="./globals.d.ts" />Do not use a triple slash reference for ./globals.d.ts, use import style instead.
/// <reference types="lodash" />Do not use a triple slash reference for lodash, use import style instead.
import { chunk } from "lodash";
export const pages = chunk([1, 2, 3, 4], 2);/// <reference lib="dom" />
/// <reference types="bun" />
import "./globals";
import { chunk } from "lodash";
export const pages = chunk([1, 2, 3, 4], 2);Options#
| Option | Default | What it does |
|---|---|---|
path | "never" | "never" reports /// <reference path="..." />. "always" allows it. |
types | "prefer-import" | "never" reports /// <reference types="..." />. "always" allows it. "prefer-import" reports it only if the file imports a module with the same name. |
lib | "always" | "never" reports /// <reference lib="..." />. "always" allows it. |
Both are reported with types: "never" and lib: "never":
{ "types": "never", "lib": "never" }2 problems/// <reference lib="dom" />Do not use a triple slash reference for dom, use import style instead.
/// <reference types="bun" />Do not use a triple slash reference for bun, use import style instead.
export const title = document.title;