Solución
solution.tsTypeScript
export function validateUser(user: { name: string; email: string; age: number }): string {
// Valida cada campo con throw
// Retorna "válido" si todos los campos son correctos
if(user.name === '') {
throw new Error("name requerido")
}
if(!user.email.includes('@')) {
throw new TypeError("email inválido")
}
if(user.age < 18) {
throw new RangeError("edad mínima 18")
}
return "válido";
}0respuestas