Typescript. What’s for?

Example №1

in js we can do tricks like this

const message = «hi»; message.toUpperCase(); // keeping in mind that it is a string /*

Читать на сайте автора.

Js. –save vs –save-dev

—save-dev is used to save the package for development purpose. Example: unit tests, minification..—save is used to save the package required for the application to run

Source

Читать на сайте автора.

Js. Bind vs Call vs Apply

Bind vs Call vs Appl from stack overflow

Call invokes the function and allows you to pass in arguments one by one.Apply invokes the function and allows

Читать на сайте автора.

Typescript. d.ts files

needed to use js code in ts code through declarations

looks like this stackoverflow post describes it the best

as i understood js files and

Читать на сайте автора.

Typescript. Modules

Modules also created to group out code. Lets look at example

hi.ts // this will be the module

export default function sayHi() { console.log(‘hi, there’);

Читать на сайте автора.

Typescript. Namespaces

namespaces allow logically group our code

namespace Animals { interface Animal { sayHi(): void } class Dog implements Animal { sayHi(): void { console.log(‘av-av’); }

Читать на сайте автора.

Typescript. Generics

function foo<T>(x: T): T { // calc return x; } console.log(foo<string>(‘hi, there’)); console.log(foo<number>(123)); // — extends for generics function foo2<T extends { name: string

Читать на сайте автора.

Typescript. Type Assertions

as it was mentioned in DataTypes post there are 2 ways of assertions through as and <type> operators

// Type assertions const myCanvas =

Читать на сайте автора.

Typescript. Static methods and fields

Here is the same idea as in C#, Java and other langs. Static methods are methods that more devoted to class rather than to instance

Читать на сайте автора.

Typescript. get / set modifiers

works only with ecmaScript2015

class Man { private _name: string = «DefaultName»; get name(): string { return this._name } set name(value: string) { console.log(‘been here’);

Читать на сайте автора.