sindresorhus/is · warning · TypeError

Expected value which is `falsy`, received value of type `${i

Error message

Expected value which is `falsy`, received value of type `${is(value)}`.

What it means

Thrown by `assertFalsy` (source/index.ts:1608) when the value is truthy. It narrows to the `Falsy` type (`false | 0 | '' | null | undefined | 0n | NaN`) on success; any truthy value — non-empty string, non-zero number, any object or array (even empty ones) — throws a TypeError with the detected type.

Source

Thrown at source/index.ts:1610

		throw new TypeError(message ?? typeErrorMessage('EnumCase', value));
	}
}

export function assertError(value: unknown, message?: string): asserts value is Error {
	if (!isError(value)) {
		throw new TypeError(message ?? typeErrorMessage('Error', value));
	}
}

export function assertEvenInteger(value: number, message?: string): asserts value is number {
	if (!isEvenInteger(value)) {
		throw new TypeError(message ?? typeErrorMessage('even integer', value));
	}
}

export function assertFalsy(value: unknown, message?: string): asserts value is Falsy {
	if (!isFalsy(value)) {
		throw new TypeError(message ?? typeErrorMessage('falsy', value));
	}
}

export function assertFiniteNumber(value: unknown, message?: string): asserts value is number {
	if (!isFiniteNumber(value)) {
		throw new TypeError(message ?? typeErrorMessage('finite number', value));
	}
}

export function assertFloat32Array(value: unknown, message?: string): asserts value is Float32Array {
	if (!isFloat32Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('Float32Array', value));
	}
}

export function assertFloat64Array(value: unknown, message?: string): asserts value is Float64Array {
	if (!isFloat64Array(value)) {
		throw new TypeError(message ?? typeErrorMessage('Float64Array', value));

View on GitHub ↗ (pinned to 7821031c66)

Solutions

  1. Check for JavaScript truthiness gotchas: `[]`, `{}`, and `'false'` are all truthy — compare explicitly if that's what you mean
  2. Parse string flags before asserting: `value === 'true'` rather than relying on truthiness
  3. If you need 'no meaningful value', assert the specific case (`assert.undefined`, `assert.null`, `assert.emptyArray`) instead of falsy

Example fix

// before
assert.falsy(process.env.DEBUG); // 'false' is truthy, throws
// after
assert.falsy(process.env.DEBUG === 'true' ? true : undefined);
// or better: const debug = process.env.DEBUG === 'true'; assert.falsy(debug || undefined)
Defensive patterns

Strategy: type-guard

Validate before calling

if (!value) {
  assert.falsy(value);
}

Type guard

function isFalsy(value: unknown): value is false | 0 | '' | null | undefined {
  return !value;
}

Try / catch

try {
  assert.falsy(value);
} catch (error) {
  if (error instanceof TypeError) {
    // value was truthy — remember empty arrays/objects and the string '0' are truthy
  } else throw error;
}

Prevention

When it happens

Trigger: Calling `assert.falsy(value)` with any truthy value, notably `[]`, `{}`, `'false'`, `'0'`, or `new Boolean(false)`, all of which are truthy in JavaScript despite looking empty or false.

Common situations: Asserting a flag or cached value is unset; env vars like `DEBUG='false'` being truthy because they're non-empty strings; empty arrays/objects passed where the author expected them to count as falsy; test assertions that a cleanup left a field cleared.

Related errors


AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31). Data as JSON: /data/errors/f1296587dd50183c.json. Report an issue: GitHub ↗.