radash icon indicating copy to clipboard operation
radash copied to clipboard

Incorrect Return Value for `isEmpty(new Error())`

Open Petri-Oosthuizen opened this issue 1 year ago • 0 comments

I encountered unexpected behavior with the isEmpty function. The expected result when calling isEmpty(new Error("Error")) is false. However, it is currently returning true.

radash version: 11.0.0 node version: v18.15.0

Reproducible code:

import { isEmpty } from "radash";

console.log(isEmpty(new Error("Error")));

Cause: An Error does not have enumerable keys which means that Object.keys(value).length from typed.ts returns 0.

Possible solutions:

  • Check for an Error type explicitly
  • Consider using Object.getOwnPropertyNames instead and adding an additional check for arrays (array.length is nonenumerable).

Petri-Oosthuizen avatar Jul 31 '23 06:07 Petri-Oosthuizen