Why You Should Avoid Using any (and What to Do Instead)
let data: any = "hello";
data.toFixed(); // No error, but will crash at runtimeWhy Overusing any is a Problem
function handleUser(user: any) {
// You might assume this is safe, but it's not
console.log(user.name.toUpperCase());
// It will crash if `user.name` is undefined or not a string
}const user: any = getUser();
user. // <- No suggestions 😭. You're flying blind.What to Use Instead
Use unknown over any
Use Partial, Pick, etc. for Flexibility
Ending notes
PreviousTyping Component Props, Events, and HooksNextTypeScript Tricks You’ll Use All the Time in React
Last updated