Table of contents
Typescript is a superset of Javascript, that adds new features and type-safety. Js is dynamically typed whereas Ts is statically Js fails during run time, ts fails during development
IDE SETUP
To ease the manual reload of the page each time we compile the file we can convert this into a node project (npm init -y) and then do npm i --save-dev lite-server
Instead of manual compilation each time, we can trigger compilation using -- watch ie tsc app.ts --watch
To compile the entire project, we can run tsc --init once creating tsconfig.json we can exclude and include files by modifying this config file
Try Debugger for Chrome vs code extension
Basics
Types
number - represents numeric values.
string - Represents textual data.
boolean - Represents true or false values.
any - Represents a dynamic or untyped value.
void - Represents the absence of a value.
null - Represents a null value.
undefined - Represents an undefined value.
object - Represents non-primitive values. ex {age:30}
Array - Represents an array of values.
Tuple - Represents an array with a fixed number of elements where each element may be of a different type.
Enum - Represents a set of named constant values.
Function - Represents a JavaScript function.
Interface - Defines the structure of an object.
Class - Represents a blueprint for creating objects.
Union - Represents a value that can be one of several types.
Intersection - Represents a value that has all the properties of multiple types.
Type Assertion - Allows you to tell the compiler the type of a variable when the type cannot be inferred.
Type Alias - Allows you to create custom types.
Literal Types - Represents a specific value, like "hello" or 42.