Skip to main content

No Use Before Define

Catch identifiers used before their declaration so read order matches definition order. Set individual options to false to allow forward references for specific categories.

Summary

The no-use-before-define rule reports any identifier that is referenced before its declaration — including variables, functions, classes, and types.

All categories are checked by default. Set individual options to false to allow forward references for specific categories.

Why Use This Rule?

  1. Prevents confusing references to variables that have not been declared yet in the read order.
  2. Lets you disable individual categories so functions and classes can reference each other freely for alphabetical organization.
  3. Catches temporal dead zone errors at lint time instead of at runtime.

Examples

Configuration

Options

warning

ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.

OptionTypeDefaultDescription
classesbooleantrueCheck class declarations.
functionsbooleantrueCheck function declarations.
ignoreFilesstring[][]File names to skip. Supports a leading-* suffix (*.test.ts), an exact path, or a trailing path segment; ** globs are not supported.
typesbooleantrueCheck identifiers used in type-annotation positions (TSTypeReference). Set to false to allow forward references to types in annotations.
variablesbooleantrueCheck const and let declarations.

Autofix

Autofix is not available for this rule. Flagged code must be updated manually.

Troubleshooting

  • Function forward references are flagged — Set functions to false if you want to allow function forward references for alphabetical organization.
  • All categories are checked by default — Set classes, functions, or types to false individually to allow forward references for specific categories.
  • Imported identifiers are never flagged — Import bindings (named, default, and namespace imports) are always exempt from this rule and cannot be re-enabled via options.