/// <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:
bunfig.toml
[lint.rules]
"@typescript-eslint/triple-slash-reference" = "off" # or "error"
Every option, set to its default:
bunfig.toml
[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
Reported:
/// <reference path="./globals.d.ts" />
/// <reference types="lodash" />
import { chunk } from "lodash";
export const pages = chunk([1, 2, 3, 4], 2);
Not reported:
/// <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":
/// <reference lib="dom" />
/// <reference types="bun" />
export const title = document.title;