prefer-native-coercion-functions
March 27, 2026 ยท View on GitHub
๐ Prefer using String, Number, BigInt, Boolean, and Symbol directly.
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ง This rule is automatically fixable by the --fix CLI option.
If a function is equivalent to String, Number, BigInt, Boolean, or Symbol, you should use the built-in one directly. Wrapping the built-in in a function is moot.
Examples
// โ
const toBoolean = value => Boolean(value);
// โ
const toBoolean = Boolean;
// โ
function toNumber(value) {
return Number(value);
}
if (toNumber(foo) === 1) {}
// โ
if (Number(foo) === 1) {}
// โ
const hasTruthyValue = array.some(element => element);
// โ
const hasTruthyValue = array.some(Boolean);
// โ
const toStringObject = value => new String(value);
// โ
const toObject = value => Object(value);
// โ
const strings = mixedData.filter((value): value is string => value);
Note
We don't check implicit coercion like:
const toString = value => '' + value;
const toNumber = value => +value;
const toBoolean = value => !!value;
It is recommended to enable the built-in ESLint rule no-implicit-coercion for a better experience.