TS = JS + Type Checking. This repository is created for my own reference/revision for the language Typescript. The repository contains code and concepts related to typescript and the various design patterns it uses. Please feel free to go through this repository and learn typescript.
- Typescript: The Complete Developer's Guide [2020] by Stephen Grider
- Understanding TypeScript - 2020 Edition by Maximilian Schwarzuller
- Typescript Language Official Docs
- Node Package Manager (npm) for Package Management. Check if
npm
was installed or not by opening the cmd/terminal and type innpm --version
, you should see the version ofnpm
you installed. - After installing
npm
, we will installtypescript
andts-node
with the commandnpm i -g typescript ts-node
in cmd/terminal. To check if thetypescript
was successfully installed, in the cmd/terminal, type in the commandtsc --help
, and you should see some output regarding typescript help. NOTE:tsc
stands fortypescript compiler
. - Download Visual Studio Code as the editor as it has extensive typescript support.
-
Help from Official Docs
-
Additional Details on Important Options in TSConfig
API Used: https://jsonplaceholder.typicode.com
Endpoints Used: /todos
Dependencies Used: npm i --save axios
- Basic Setup: Commit Details
- Executing TS Code Using
tsc
,node
&ts-node
: Commit Details - Introducing a Bug: Commit Details
- Catching Errors with Typescript using
interface
: Commit Details - Introducing Another Bug using a Function: Commit Details
- Catching Errors related to a Function: Commit Details
- What are Types? More on Types. Where do we use Types? ← READ THIS BEFORE MOVING AHEAD ⭐⭐⭐
- Examples of Types: Commit Details
- What is Type Annotation & Type Inference?
- Type Annotations with Variables: Commit Details
- Basic Type Annotations with Arrays, Classes & Object Literals: Commit Details
- Basic Type Annotation with Functions: Commit Details
- Understanding Type Inference In-Depth: Commit Detail #1 & Commit Detail #2 ← VERY IMPORTANT ⭐⭐⭐
- More on Annotations Around Functions: Commit Details
- Inference Around Functions: Commit Details
- Annotations for Anonymous Functions: Commit Details
- Functions returning
void
andnever
typed values: Commit Details - Destructuring Objects with Type Annotations: Commit Details
- Complex Example of Destructuring Objects with Type Annotations: Commit Details
- Arrays in Typescript: Commit Details
- Why Typed Arrays?: Commit Details
- Multiple Types in Arrays: Commit Details
- Tuples in Action && Intro to Type Aliasing: Commit Details
- Why Tuples & Why Not Tuples? Commit Details
- Working with
enum
s: Commit DetailsEnums
are enumerated global constant identifiers that automatically start with 0.
- Literal Types & Union Types: Commit Details
- The
unknown
type: Commit Details
- What are Classes? — A
class
is a blueprint to create an object with some fields (values) and methods (functions) to represent an entity/thing/real-world-object - Classes in Action: Commit Details
- Class with
constructor()
: Commit Details constructor()
function and thethis
keyword: Commit #1 & Commit #2private
&public
Access Modifiers: Commit #1 & Commit #2- Shorthand Initialization of Properties in a
class
: Commit #1 & Commit #2 readonly
Properties: Commit Details- Inheritance: Commit Details
- Overriding Properties & The
protected
Access Modifier: Commit Details - Getters & Setters using
get
&set
: Commit Details static
Methods & Properties: Commit Detailsabstract
Classes: Commit Details- Singleton Pattern &
private
constructors: Commit Details - What are Interfaces?
interface
creates a new type, describing the property names and value types of an object.interface
s is a pure TS feature and so, it is not available in JS. If we look into a JS file which is converted from a TS file (which had interface related code), we will see that none of theinterface
s are compiled to its respective JS version becauseinterface
s are native to TS, and not JS.
- Long Type Annotations: Commit Details
- Fixing Long Annotations with
interface
s: Commit Details - Syntax Around Interfaces: Commit Details
- Using
interface
s withclass
es: Commit Details readonly
Interface Properties: Commit Detailsextend
ing Interfaces: Commit Details- Functions in Interfaces: Commit Details
- Code Reuse with Interfaces: Commit Details
interface
s as Function Types: Commit Details- Optional Parameters & Properties for an
interface
: Commit Details
- Intersection Types: Commit Details
- More on Type Guards: Commit Details
- Discriminated Unions: Commit Details
- Type Casting - Not much of casting, but informing: Commit Details
- Index Properties ⭐⭐: Commit Details
- Function Overloads: Commit Details
- Optional Chaining: Commit Details
- Nullish Coalescing: Commit Details
- Built-in Generics & What are Generics? Commit Details
- Creating a Generic Function: Commit Details
- Working with Constraints: Commit Details
- Generic Function w. Custom Interface: Commit Details
- The
keyof
Constraint: Commit Details - Generic Classes: Commit Details
- Generic Utility Types like
Partial<>
&Readonly<>
: Commit Details - Generic Types vs Union Types: Commit Details
Open tsconfig.json
and set "target": "es6"
& "experimentalDecorators": true
before moving ahead with the content below.
Note: For more info on tsconfig.json
related to this section, check this file here
- A First Class Decorator: Commit Details
- Working with Decorator Factories: Commit Details
- Using Decorator(s) to Manipulate the DOM: Commit Details
- Adding Multiple Decorators to a single Class: Commit Details
- Property Decorators: Commit Details
- Accessor, Method & Parameter Decorators: Commit Details
- When Do Decorators Execute? Commit Details
- Returning (& Modifying) a Class in Class Decorator: Commit Details
- Decorator Return Types for Method & Accessor Decorators (Read about
Object.defineProperty()
before going ahead): Commit Details - Returning Descriptor From A Method Decorator (Ex: Creating an
@Autobind
Decorator): Commit Details - Validation with Decorators
- Why to Validate Using Decorators? Commit Details
- Implementation of Validation Using Decorators: Commit #1, Commit #2 [Shortening the code using DRY] & Commit #3 [Bug Fixes]
- Libraries that use/rely heavily on Decorators are the following
- typestack/class-validator — Decorator based property validation for classes.
- Angular — Frontend JS/TS Framework that relies heavily on decorator implementations.
- NestJS — A progressive Node.js framework for building efficient, reliable and scalable server-side applications, which also uses a lot of decorator based meta programming constructs for making a
GET
,POST
, etc routes.