0.4 - TypeScript Intro
I was going to create an exercise to introduce TypeScript, but there are already so many resources that have been created to do accomplish this very goal! Instead, please take 10-15 minutes to complete the following on learn-ts.org:
For now, we’re only going to need the very basics of what TypeScript has to offer, namely, the types. Fear not, we’ll learn more advanced TypeScript features over the course of the semester!
Anything else?
The one thing I will say for now is sometimes you will get a TS error that is fixed by changing a variable to the any
type. Do not do this. I repeat: DO NOT DO THIS!! This is a huge red flag and an indicator that you’re not sure what you’re doing.
This is a great article describing why you shouldn’t use the any
type if you’re curious.
Why shouldn’t we use any again?
- It yields the compiler obsolete. We’re telling the compiler, “Help not needed, I got this”.
- We’re passing on an opportunity to document the code as we write it.
- Our first line of defense is down.
- In a dynamic language, we assume that things can have any type, and the patterns we employ follow this assumption. If we start using a statically typed language as a dynamic one, then we’re fighting the paradigm.
- As we continue to make changes to the codebase, there’s nothing to guide/help us.
- With great freedom comes great responsibility (the compilers). Don’t turn into a compiler, use one.
You have been warned.