TypeScript Tricks You’ll Use All the Time in React
Destructuring with Types
const user = { name: "Alice", age: 30 };
const { name } = user;interface User {
name: string;
age: number;
}
const user: User = { name: "Alice", age: 30 };
const { name, age }: User = user; // Typed destructuring
console.log("name: ", name); // "name: Alice"
console.log("age: ", age); // "age: 30"function greet({ name }: { name: string }) {
console.log(`Hi, ${name}`);
}Spread Operator with Typed Objects
What is the Spread Operator?
🧠 Use the spread operator instead of direct mutation to keep your data.
Default Values with Destructuring
Rename in Destructuring
Typing Arrays and Spread
Last updated