⬅️ FEM TypeScript Fundamentals #✅
Nullish values
null
nullmeans: there is a value, and that value is nothing.
undefined
undefinedmeans the value isn’t available (yet?)
let notDefined: undefined = null;
notDefined;
// Result:
type error: Type 'null' is not assignable to type 'undefined'.void
voidshould exclusively be used to describe that a function’s return value should be ignored
Non-null assertion operator
- aka optional chaining, the non-null assertion operator (
!) is used to cast away the possibility that a value might benullorundefined.
type GroceryCart = {
fruits?: { name: string; qty: number }[]
vegetables?: { name: string; qty: number }[]
}
const cart: GroceryCart = {}
cart.fruits.push({ name: "kumkuat", qty: 1 })
cart.fruits!.push({ name: "kumkuat", qty: 1 })Definite assignment operator
!:, same as above but used on class fields instead