no-useless-undefined
March 27, 2026 ยท View on GitHub
๐ Disallow useless undefined.
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ง This rule is automatically fixable by the --fix CLI option.
undefined is the default value for new variables, parameters, return statements, etcโฆ so specifying it doesn't make any difference.
Where passing undefined as argument is required is due to bad TypeScript types in functions, in which case you can use checkArguments: false option.
Using undefined as arrow function body sometimes make the purpose more explicit. You can use the checkArrowFunctionBody: false option to allow this.
Examples
// โ
let foo = undefined;
// โ
let foo;
// โ
const {foo = undefined} = bar;
// โ
const {foo} = bar;
// โ
const noop = () => undefined;
// โ
const noop = () => {};
// โ
function foo() {
return undefined;
}
// โ
function foo() {
return;
}
// โ
function* foo() {
yield undefined;
}
// โ
function* foo() {
yield;
}
// โ
function foo(bar = undefined) {
}
// โ
function foo(bar) {
}
// โ
function foo({bar = undefined}) {
}
// โ
function foo({bar}) {
}
// โ
foo(undefined);
// โ
foo();
Options
Type: object
checkArguments
Type: boolean
Default: true
Disallow the use of undefined at the end of function call arguments. Pass checkArguments: false to disable checking them.
// โ
/* eslint unicorn/no-useless-undefined: ["error", {"checkArguments": true}] */
foo(bar, baz, undefined);
// โ
/* eslint unicorn/no-useless-undefined: ["error", {"checkArguments": false}] */
foo(bar, baz, undefined);
checkArrowFunctionBody
Type: boolean
Default: true
Disallow the use of undefined as arrow function body. Pass checkArrowFunctionBody: false to disable checking them.
/* eslint unicorn/no-useless-undefined: ["error", {"checkArrowFunctionBody": true}] */
// โ
const foo = () => undefined;
/* eslint unicorn/no-useless-undefined: ["error", {"checkArrowFunctionBody": false}] */
// โ
const foo = () => undefined;
Conflict with ESLint array-callback-return and getter-return rules
We recommend setting allowImplicit option to true for these ESLint rules:
{
"rules": {
"array-callback-return": [
"error",
{
"allowImplicit": true
}
],
"getter-return": [
"error",
{
"allowImplicit": true
}
]
}
}