- Helps catch errors during development
- Uses 'type annotations' to analyze code
- Only active during development
- Doesn't provide any performance optimization
Syntax+Features vs Design Patterns with TS
- Syntax+Features: What is an interface? What is the syntax for defining an interface?:
- Understand basic types in TS
- Function typing + annotations
- Type definition files
- Arrays in TS
- Module systems
- Classes + Refresher on OOP
- Projects
- Design Patterns with TS: How to use interfaces to write reusable code
- Projects
Type- The different properties + functions that a value has:
- Used by the typescript compiler to analyze the code for errors
- Allow other engineers to understand the types in the codebase
- Primitive Types: number, string, boolean, symbol, void, null, undefined
- Object Types: functions, classes, arrays, objects
- Type Annotations + Inference apply to variables, Functions, Objects
- Type Annotations: Code added to tell TypeScript what type of value a variable will refer to
- Type Inference: TS tries to figure out what type of value a variable refers to. If declaration and initialization are on the same line, TS will figure out the type annotation automatically.
- When we declare a variable on one line then initialize it later
- When we want a variable to have a type that can't be inferred
- When a function returns the "any" type and we need to clarify the value
Always!
Type Annotations for functions: Code we add to tell TS what type of arguments a function will receive and what type of values it will return Type inference for functions: TS tries to figure out what type of value a function will return.
- Use typed Arrays any time you need to represent a collection of records with some a arbitrary sort order
- A Tuple s an Array-like structure where each element represents some property of a record
Interfaces: Creates a new type, describing the property names and values of an object.
- General Strategy for reusable code in TS
- Create functions that accept arguments that are typed with interfaces
- Objects/Classes can decide to 'implement' a given interface to work with a function
- Public: This method can be called anywhere, anytime
- Private This method can only be called by other methods in this class
- Protected This method can be called by other methods in this class, or by other methods in child classes.