unicorn/no-typeof-undefined
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-typeof-undefined": "error",
},
},
];function foo(bar) {
if (typeof bar === 'undefined') {}
}if (typeof foo.bar !== 'undefined') {}function foo(bar) {
if (bar === undefined) {}
}if (foo.bar !== undefined) {}Examples from the ESLint documentation.
unicorn/no-typeof-undefined
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-typeof-undefined": "error",
},
},
];unicorn/no-typeof-undefined
unicorn plugin · pedantic
{
"rules": {
"unicorn/no-typeof-undefined": "error"
}
}Biome does not have this rule.
Disallow assigning this to a variable.
Disallow using 1 as the depth argument of Array#flat().
Disallow the use of objects as default parameters.
Disallow using .length or Infinity as the deleteCount or skipCount argument of Array#{splice,toSpliced}().
Prefer Array#toSorted() over Array#sort().
Disallow using .length or Infinity as the end argument of {Array,String,TypedArray}#slice().