I need to sanitize the email in my user object before pushing it to my sqlite database. This is necessary during both user creation and updates. Here's what I have so far:
export const addUser = (user: CreateUser) => {
db.prepare(sqlInsertUser).run(cleanEmail(user))
}
export const updateUser = (user: UpdateUser) => {
db.prepare(sqlUpdateUser).run(cleanEmail(user))
}
type CreateUser = {
email: string
password: string
permissionLevel?: number
}
type UpdateUser = {
email: string
password: string
}
Now, I'm working on:
const cleanEmail = (user: ?) => {
user.email = user.email.trim()
return user
}
However, I'm unsure of what type to assign to the 'user' parameter. How do I handle multiple types and return the updated object?
Is there a way to implement this effectively, even with additional types that all include the email property?