no-use-before-define
Added in v0.4.2Configuration
rslint.config.ts
Rule Details
Disallow the use of variables before they are defined.
This rule extends the base ESLint no-use-before-define rule to add support for TypeScript-specific constructs like type, interface, and enum declarations.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
functions(boolean, defaulttrue) - Whether to check function declarationsclasses(boolean, defaulttrue) - Whether to check class declarationsvariables(boolean, defaulttrue) - Whether to check variable declarationsenums(boolean, defaulttrue) - Whether to check enum declarationstypedefs(boolean, defaulttrue) - Whether to check type/interface declarationsignoreTypeReferences(boolean, defaulttrue) - Whether to ignore references in type annotationsallowNamedExports(boolean, defaultfalse) - Whether to allow references in named exports
Also accepts "nofunc" as a shorthand for { functions: false }.
Differences from ESLint
rslint also ships the core no-use-before-define rule, which gained TypeScript
support in ESLint 10 and takes the same options. Enable one or the other — the
two disagree in a few places, because this rule extends an older version of the
core rule:
- Code that reads a class binding while the class itself is still being defined
—
class C extends C {},class C { [C](){} },const C = class { static x = C }— is reported by the core rule and not by this one. - A class field initializer or static block is an ordinary separate scope here,
so
classes,variables, andenumsexempt references from inside one. The core rule treats static initializers as part of the surrounding code, and still reports them. ignoreTypeReferencescovers every type position here — includingimplementsclauses, qualified type names, and the exported name ofexport = X/export default X. The core rule only exempts direct type references andtypeofqueries.- References from a function/constructor type or call/construct/method signature are never reported here, including its parameter and return types.
- A reference that resolves to a string-literal enum member (
enum E { b = a, "a" = 1 }) is not reported here, because such a member declares no identifier. The core rule measures it from the literal and reports it.