TypeScript Tidbits
Oct 3, 2021 08:01 PM

Start using TypeScript

Assuming you already use JavaScript - get TypeScript integrated. It doesn't matter if you don't know it. I use Next.js and it was easy to get going -
The IDE support is worth it, start changing your file names to .ts or .tsx and you'll start getting feedback from your IDE.

Destructuring and defining props

const CoolComponent = (props) => {
	const user = props.user
	const title = props.title
I used to write code like that. It works, but you don't get IDE support with it. If you write the following instead:
const CoolComponent = ({ user, title }) => { }
Now if I hover my mouse over CoolComponent:
notion image
We can even make it cleaner:
const CoolComponent = ({ user, title }): {
	user: string,
	title: string
	} => {
	// rest of component code
Now we get that red line support, you can catch the errors before they happen, otherwise we would be working with a title is undefined error.