What is TypeScript?
TypeScript allows specifying the types of data being passed around within the code, and has the ability to report errors when the types don’t match.
TypeScript uses compile time type checking. Which means it checks if the specified types match before running the code, not while running the code.
TypeScript simple types(primitives)
boolean- true or false values
number- whole numbers and floating point values
string- text values like "TypeScript Rocks"
bigint- whole numbers and floating point values, but allows larger negative and positive numbers than the
symbol- are used to create a globally unique identifier.
TypeScript special types
TypeScript has special types that may not refer to any specific type of data.
any- is a type that disables type checking and effectively allows all types to be used.
unknown- is a similar, but safer alternative to
any. TypeScript will prevent
unknowntypes from being used
never- effectively throws an error whenever it is defined.
A tuple is a typed array with a pre-defined length and types for each index.
The order of value types matters for Tuples.
// define our tuple
let ourTuple: [number, boolean, string];
// initialize correctly
ourTuple = [5, false, 'Coding God was here'];