I'm trying to delete the password
key in a user object in a typesafe way but typescript keeps complaining.
const user = db.findUnique({where: email:input.email});
// returning user without password
// OPTION 1 - eslint disable doesn't remove the yellow squiggly on the password variable
// @eslint-disable-next-line @typescript-eslint/no-unused-vars
const { password, ...userWithoutPassword } = user;
return userWithoutPassword;
// OPTION 2 - Unsafe return of an `any` typed value.eslint@typescript-eslint/no-unsafe-assignment
return omit(user, "password"); // using lodash
// this also leads to the same error
const userWithoutPassword: Omit<User, "password"> = omit(user, "password");
return userWithoutPassword;
// OPTION 3 - The operand of a 'delete' operator must be optional.
// I don't want to change the type definition of User to make password optional. It should be a new type
delete user.password;
return user;
What's the appropriate way to do this?