79240790

Date: 2024-12-01 02:13:12
Score: 1
Natty:
Report link

The provided function has some type definition issues in its return type. Specifically, { [K in keyof O]: O[K] extends undefined ? never : O[K] } would produce a type incompatible with the actual returned object.

Here’s the implementation

function objectWithoutUndefined<O extends Record<string, unknown>>(
  obj: O,
): Partial<O> {
  Object.keys(obj).forEach((key) => {
    if (obj[key] === undefined) {
      delete obj[key];
    }
  });
  return obj;
}
Reasons:
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Tharuka Deshan