> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-undef

[Added in v0.3.3](https://github.com/web-infra-dev/rslint/releases/tag/v0.3.3)
## Configuration


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-undef': 'error',
    },
  },
]);
```

Disallow the use of undeclared variables.

This rule reports identifiers that reference variables which have not been declared via `var`, `let`, `const`, `function`, `class`, `import`, or as a parameter.

Resolution follows ESLint scope semantics: bindings declared or imported in the current file, the standard language globals selected by `languageOptions.ecmaVersion`, and names declared through [`languageOptions.globals`](https://rslint.rs/config/language-options.md#languageoptionsglobals) or a `/* global */` comment. `ecmaVersion` defaults to `"latest"`.

TypeScript's TypeChecker does not alter the result. DOM, Node, cross-file, and ambient `.d.ts` names are not implicit ESLint globals, even when TypeScript can resolve them. Declare host globals such as `console`, `window`, `process`, and `setTimeout` through `languageOptions.globals` or a `/* global */` comment. TypeScript projects normally leave this core rule disabled because `tsc` already reports undeclared names.

For browser, Node.js, worker, and other runtime names, use the `globals` catalog exported by `@rslint/core` instead of listing every name manually. Scope each environment to the files where it exists; no runtime environment is enabled by default. See [Configuring runtime globals](https://rslint.rs/config/language-options.md#languageoptionsglobals) for examples.

## Options

### `typeof`

Type: `boolean`
Default: `false`

When set to `true`, `typeof` expressions will be checked for undeclared variables. By default, `typeof` of an undeclared variable does not trigger a warning, since `typeof` returns `"undefined"` for undeclared variables without throwing a ReferenceError.

## Examples

### Invalid

```js
a = 1; // 'a' is not defined.
var x = b; // 'b' is not defined.
undeclaredFunc(); // 'undeclaredFunc' is not defined.
```

With `{ "typeof": true }`:

```js
typeof x === 'string'; // 'x' is not defined.
```

### Valid

```js
var a = 1;
a;

function f() {}
f();

typeof maybeUndefined === 'string';
```

## Differences from ESLint

- In TypeScript files, rslint applies `languageOptions.ecmaVersion` to runtime
  ECMAScript globals. ESLint with `@typescript-eslint/parser` uses that parser's
  default ESNext library instead. For example, with `ecmaVersion: 2019`, rslint
  reports `BigInt(1)` unless `BigInt` is configured as a global, while ESLint
  does not. With the default parser library, type-only ESNext names such as
  `Record` remain available in both.

## Original Documentation

- [ESLint: no-undef](https://eslint.org/docs/latest/rules/no-undef)
- [Source code](https://github.com/eslint/eslint/blob/v10.9.1/lib/rules/no-undef.js)
