Skip to content

typescript/triple-slash-reference Correctness

This rule is turned on by default.

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:

ts
/// <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:

ts
/// <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:

bash
oxlint --deny typescript/triple-slash-reference
json
{
  "rules": {
    "typescript/triple-slash-reference": "error"
  }
}

References

Released under the MIT License.