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, and this page is available as Markdown at https://rslint.rs/rules/unicorn/no-typeof-undefined.md.
close

no-typeof-undefined

Added in v0.9.5

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-typeof-undefined': 'error',
    },
  },
]);

Disallow comparing undefined using typeof.

Prefer a direct comparison:

// Incorrect
if (typeof value === 'undefined') {
}

// Correct
if (value === undefined) {
}

By default, references that resolve to globals are ignored because removing typeof can turn an existence check into a ReferenceError. Set checkGlobalVariables: true to report those cases as suggestions instead of autofixes.

This port follows eslint-plugin-unicorn v75.0.0, including converting ==/!= to strict equality, ASI-sensitive replacements, and multiline return/throw handling. Autofixes are intentionally withheld for the browser document.all legacy object, including binding-aware globalThis, window, self, frames, top, and parent Window aliases, because replacing typeof … === 'undefined' there would change runtime behavior.