close

no-typeof-undefined

Unreleased

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.