I LOVE TS ❤ and truly think types are the best way to document the code and it helps a lot in debugging, even future designing made easy when you have a model in front of you…The TS type system is awesome even though using types have no meaning in terms of memory allocation/management (like in Rust lang for e.g.).

Let’s simplify the typescript definition:

TypeScript provides static typing through type annotations to enable type checking at compile time. This is optional and can be ignored to use the regular dynamic typing of JavaScript.

Name dropping <T>: (terms: T)

Firstly — What is a Type system?

A type system associates a type with each computed value and, by examining the flow of these values, attempts to ensure or prove that no type errors can occur.

Kind of cool having a set of rules aimed to reduce possibilities of bugs isn’t it?

Static typing: Types checked before run-time (tracking bugs before shifting your code..).

Dynamically-typed: Type checked mostly at run time. (runtime issues are more expensive if missed).

BTW the mix combination of both strongly and weekly typing (like when using any) is called: “gradual typing.”

Type annotations: (just a fancy name to something your’e familiar with..) used to enforce type checking. e.g as is (object with members) or using the type / interface declarations.

function drive(driver: {name: string, age: number},

car: { brand: string, maxSpeed: number }) {

}



// OR



type Driver = {name: string, age: number};



// OR



interface IDriver {

name: string;

age: number

}

Structural typing:

I recently watched the TypeScript: Static Types for JavaScript lecture by Anders Hejlsberg, it’s really good and he explains TS as a Structural type system

Structural typing is a way of relating types based solely on their members.

Relate types based on their members? The following shows possibly 2 different types but both have the same members thus could be assigned one to the other:

interface INode<T> {

data: string;

parent: T;

children: INode<INode<T>>[];

}



type Item<T> = {

data: string;

parent: T;

children: Item<Item<T>>[];

} let foo: INode<null>;

let bar: Item<null>;



foo = bar;

The basic rule for TypeScript’s structural type system is that x is compatible with y if y has at least the same members as x.

That’s all, I hope you enjoyed my 2 min of high level statically typed javascript (using typescript)! Cheers,

Liron.