• Complain

it-ebooks - TypeScript Deep Dive

Here you can read online it-ebooks - TypeScript Deep Dive full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2017, publisher: iBooker it-ebooks, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

it-ebooks TypeScript Deep Dive
  • Book:
    TypeScript Deep Dive
  • Author:
  • Publisher:
    iBooker it-ebooks
  • Genre:
  • Year:
    2017
  • Rating:
    4 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 80
    • 1
    • 2
    • 3
    • 4
    • 5

TypeScript Deep Dive: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "TypeScript Deep Dive" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

it-ebooks: author's other books


Who wrote TypeScript Deep Dive? Find out the surname, the name of the author of the book and a list of all author's works by series.

TypeScript Deep Dive — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "TypeScript Deep Dive" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
@types
@types

Definitely Typed is definitely one of TypeScript's greatest strengths. The community has effectively gone ahead and documented the nature of nearly 90% of the top JavaScript projects out there.

This means that you can use these projects in a very interactive and exploratory manner, no need to have the docs open in a seperate window and making sure you don't make a typo.

Using @types

Installation is fairly simple as it just works on top of npm. So as an example you can install type definitions for jquery simply as:

npm install @types/jquery --save-dev

@types supports both global and module type definitions.

Global @types

By default any definitions that support global consumption are included automatically. E.g. for jquery you should be able to just start using $globally in your project.

However for libraries (like jquery) I generally recommend using modules:

Module @types

After installation, no special configuration is required really. You just use it like a module e.g.:

import * as $ from "jquery" ; // Use $ at will in this module :)
Controlling Globals

As can be seen having a definition that supports global leak in automatically can be a problem for some team so you can chose to explicitly only bring in the types that make sense using the tsconfig.jsoncompilerOptions.types e.g.:

{ "compilerOptions" : { "types" : [ "jquery" ] }}

The above shows a sample where only jquery will be allowed to be used. Even if the person installs another definition like npm install @types/node its globals (e.g. process) will not leak into your code until you add them to the tsconfig.json types option.

Table of Contents
  1. 1.1
  2. 1.2
    1. 1.2.1
  3. 1.3
    1. 1.3.1
    2. 1.3.2
    3. 1.3.3
    4. 1.3.4
    5. 1.3.5
    6. 1.3.6
  4. 1.4
    1. 1.4.1
      1. 1.4.1.1
      2. 1.4.1.2
    2. 1.4.2
    3. 1.4.3
    4. 1.4.4
    5. 1.4.5
    6. 1.4.6
    7. 1.4.7
    8. 1.4.8
    9. 1.4.9
    10. 1.4.10
    11. 1.4.11
    12. 1.4.12
    13. 1.4.13
  5. 1.5
    1. 1.5.1
      1. 1.5.1.1
      2. 1.5.1.2
    2. 1.5.2
    3. 1.5.3
      1. 1.5.3.1
      2. 1.5.3.2
    4. 1.5.4
    5. 1.5.5
  6. 1.6
  7. 1.7
  8. 1.8
    1. 1.8.1
    2. 1.8.2
    3. 1.8.3
      1. 1.8.3.1
      2. 1.8.3.2
    4. 1.8.4
    5. 1.8.5
    6. 1.8.6
    7. 1.8.7
    8. 1.8.8
    9. 1.8.9
    10. 1.8.10
    11. 1.8.11
    12. 1.8.12
    13. 1.8.13
    14. 1.8.14
    15. 1.8.15
    16. 1.8.16
    17. 1.8.17
    18. 1.8.18
    19. 1.8.19
    20. 1.8.20
    21. 1.8.21
  9. 1.9
  10. 1.10
    1. 1.10.1
    2. 1.10.2
  11. 1.11
    1. 1.11.1
  12. 1.12
    1. 1.12.1
    2. 1.12.2
    3. 1.12.3
    4. 1.12.4
    5. 1.12.5
    6. 1.12.6
    7. 1.12.7
    8. 1.12.8
    9. 1.12.9
    10. 1.12.10
    11. 1.12.11
    12. 1.12.12
    13. 1.12.13
    14. 1.12.14
    15. 1.12.15
    16. 1.12.16
    17. 1.12.17
    18. 1.12.18
    19. 1.12.19
    20. 1.12.20
    21. 1.12.21
  13. 1.13
  14. 1.14
  15. 1.15
    1. 1.15.1
    2. 1.15.2
      1. 1.15.2.1
      2. 1.15.2.2
      3. 1.15.2.3
    3. 1.15.3
    4. 1.15.4
      1. 1.15.4.1
    5. 1.15.5
      1. 1.15.5.1
      2. 1.15.5.2
      3. 1.15.5.3
      4. 1.15.5.4
      5. 1.15.5.5
    6. 1.15.6
      1. 1.15.6.1
      2. 1.15.6.2
    7. 1.15.7
      1. 1.15.7.1
      2. 1.15.7.2
    8. 1.15.8
Arrow Functions
Arrow Functions

Lovingly called the fat arrow (because -> is a thin arrow and => is a fat arrow) and also called a lambda function (because of other languages). Another commonly used feature is the fat arrow function ()=>something. The motivation for a fat arrow is:

  1. You don't need to keep typing function
  2. It lexically captures the meaning of this
  3. It lexically captures the meaning of arguments

For a language that claims to be functional, in JavaScript you tend to be typing function quite a lot. The fat arrow makes it simple for you to create a function

var inc = (x)=>x+;

this has traditionally been a pain point in JavaScript. As a wise man once said "I hate JavaScript as it tends to lose the meaning of this all too easily". Fat arrows fix it by capturing the meaning of this from the surrounding context. Consider this pure JavaScript class:

function Person ( age ) { this .age = age; this .growOld = function () { this .age++; }} var person = new Person();setTimeout(person.growOld, 1000 );setTimeout( function () { console .log(person.age); }, 2000 ); // 1, should have been 2

If you run this code in the browser this within the function is going to point to window because window is going to be what executes the growOld function. Fix is to use an arrow function:

function Person ( age ) { this .age = age; this .growOld = () => { this .age++; }} var person = new Person();setTimeout(person.growOld, 1000 );setTimeout( function () { console .log(person.age); }, 2000 ); // 2

The reason why this works is the reference to this is captured by the arrow function from outside the function body. This is equivalent to the following JavaScript code (which is what you would write yourself if you didn't have TypeScript):

function Person ( age ) { this .age = age; var _this = this ; // capture this this .growOld = function () { _this.age++; // use the captured this }} var person = new Person();setTimeout(person.growOld, 1000 );setTimeout( function () { console .log(person.age); }, 2000 ); // 2

Note that since you are using TypeScript you can be even sweeter in syntax and combine arrows with classes:

class Person { constructor (public age:number) {} growOld = () => { this .age++; }} var person = new Person();setTimeout(person.growOld, 1000 );setTimeout( function () { console .log(person.age); }, 2000 ); // 2

A sweet video about this pattern

Tip: Arrow Function Need

Beyond the terse syntax, you only need to use the fat arrow if you are going to give the function to someone else to call. Effectively:

var growOld = person.growOld; // Then later someone else calls it: growOld();

If you are going to call it yourself, i.e.

person.growOld();

then this is going to be the correct calling context (in this example person).

Tip: Arrow Function Danger

In fact if you want thisto be the calling context you should not use the arrow function. This is the case with callbacks used by libraries like jquery, underscore, mocha and others. If the documentation mentions functions on this then you should probably just use a function instead of a fat arrow. Similarly if you plan to use arguments don't use an arrow function.

Tip: Arrow functions with libraries that use this

Many libraries do this e.g. jQuery iterables (one example http://api.jquery.com/jquery.each/) will use

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «TypeScript Deep Dive»

Look at similar books to TypeScript Deep Dive. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «TypeScript Deep Dive»

Discussion, reviews of the book TypeScript Deep Dive and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.