When should you consider TypeScript? — If the code base is relatively large — If you ever plan on refactoring — If you have a decently large group of people working on the code base — If you're spending a non-zero amount of time writing unit tests
if you wanted some like a tuple from Swift or Python, you can do that as well. let point: [number, number] = [7, 5]; This will only allow arrays with two number elements. This helps ensure that you're getting what you think you're getting.
Functions JavaScript: const numberToString = (n) => n.toString(); TypeScript: const numberToString = (n: number): string => n.toString(); The TypeScript compiler keeps track of inputs and outputs to make sure nothing strange will happen at runtime.
What about functional programming? JavaScript: const curriedAdd = a => b => a + b; TypeScript: const curriedAdd = (a: number): (b: number) => number => (b) => a + b; curriedAdd(1)(2); const add2 = curriedAdd(2); add2(5); See it with Intellisense.
Okay, so remember this syntax for arrays? let numbers = Array; let names = Array; That thing in the <> brackets is called a generic. It's not super wrong to think of it as a variable for a type.
Namespaces Think about them like objects of methods that you can split across files. namespace Validation { export interface StringValidator { isAcceptable(s: string): boolean; } }