TypeScript Tutorial - RxJS, ggplot2, Python Data ...

 TypeScript

About the Tutorial

TypeScript lets you write JavaScript the way you really want to. TypeScript is a typed

superset of JavaScript that compiles to plain JavaScript.

TypeScript is pure object oriented with classes, interfaces and statically typed like C# or

Java. The popular JavaScript framework Angular 2.0 is written in TypeScript. Mastering

TypeScript can help programmers to write object-oriented programs and have them

compiled to JavaScript, both on server side and client side.

Audience

Programmers coming from Object Oriented world will find it easy to use TypeScript. With

the knowledge of TypeScript, they can build web applications much faster, as TypeScript

has good tooling support.

Prerequisites

As a reader of this tutorial, you should have a good understanding of OOP concepts and

basic JavaScript, to make the most of this tutorial.

Copyright & Disclaimer

? Copyright 2016 by Tutorials Point (I) Pvt. Ltd.

All the content and graphics published in this e-book are the property of Tutorials Point (I)

Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish

any contents or a part of contents of this e-book in any manner without written consent

of the publisher.

We strive to update the contents of our website and tutorials as timely and as precisely as

possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.

Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our

website or its contents including this tutorial. If you discover any errors on our website or

in this tutorial, please notify us at contact@

i

TypeScript

Table of Contents

About the Tutorial .................................................................................................................................... i

Audience .................................................................................................................................................. i

Prerequisites ............................................................................................................................................ i

Copyright & Disclaimer ............................................................................................................................. i

Table of Contents .................................................................................................................................... ii

1.

TYPESCRIPT ¨C OVERVIEW..................................................................................................... 1

What is TypeScript?................................................................................................................................. 1

Features of TypeScript............................................................................................................................. 1

Why Use TypeScript? .............................................................................................................................. 2

Components of TypeScript ...................................................................................................................... 3

2.

TYPESCRIPT ¨C ENVIRONMENT SETUP .................................................................................. 4

TypeScript ©¤ Try it Option Online ............................................................................................................ 4

Local Environment Setup......................................................................................................................... 5

Installing Node.js..................................................................................................................................... 5

IDE Support ............................................................................................................................................. 8

Visual Studio Code .................................................................................................................................. 8

Brackets ................................................................................................................................................ 11

3.

TYPESCRIPT ©¤ BASIC SYNTAX.............................................................................................. 14

Your First TypeScript Code .................................................................................................................... 14

Compile and Execute a TypeScript Program .......................................................................................... 14

Compiler Flags ....................................................................................................................................... 15

Identifiers in TypeScript ........................................................................................................................ 16

TypeScript ©¤ Keywords .......................................................................................................................... 16

Comments in TypeScript ....................................................................................................................... 17

ii

TypeScript

TypeScript and Object Orientation ........................................................................................................ 18

4.

TYPESCRIPT ¨C TYPES .......................................................................................................... 20

The Any type ......................................................................................................................................... 20

Built-in types ......................................................................................................................................... 20

5.

TYPESCRIPT ¨C VARIABLES ................................................................................................... 22

Variable Declaration in TypeScript ........................................................................................................ 22

Type Assertion in TypeScript ................................................................................................................. 24

Inferred Typing in TypeScript ................................................................................................................ 25

TypeScript Variable Scope ..................................................................................................................... 25

6.

TYPESCRIPT ©¤ OPERATORS................................................................................................. 28

What is an Operator? ............................................................................................................................ 28

Arithmetic Operators ............................................................................................................................ 28

Relational Operators ............................................................................................................................. 30

Logical Operators .................................................................................................................................. 32

Short-circuit Operators (&& and ||) ...................................................................................................... 33

Bitwise Operators ................................................................................................................................. 34

Assignment Operators........................................................................................................................... 36

Miscellaneous Operators ...................................................................................................................... 38

Type Operators ..................................................................................................................................... 39

7.

TYPESCRIPT ©¤ DECISION MAKING ...................................................................................... 41

The if Statement.................................................................................................................................... 42

The if¡­else Statement........................................................................................................................... 43

The else¡­if Ladder ................................................................................................................................ 45

The switch¡­case Statement .................................................................................................................. 46

iii

TypeScript

8.

TYPESCRIPT ©¤ LOOPS ......................................................................................................... 51

The while Loop ...................................................................................................................................... 52

The for Loop .......................................................................................................................................... 54

The for...in loop..................................................................................................................................... 56

The do¡­while loop ................................................................................................................................ 57

The break Statement ............................................................................................................................. 60

The continue Statement ........................................................................................................................ 61

The Infinite Loop ................................................................................................................................... 63

9.

TYPESCRIPT ¨C FUNCTIONS ................................................................................................. 65

Defining a Function ............................................................................................................................... 65

Calling a Function .................................................................................................................................. 65

Returning Functions .............................................................................................................................. 66

Parameterized Function ........................................................................................................................ 68

Optional Parameters ............................................................................................................................. 69

Rest Parameters .................................................................................................................................... 70

Default Parameters ............................................................................................................................... 72

Anonymous Function ............................................................................................................................ 73

The Function Constructor ...................................................................................................................... 74

Recursion and TypeScript Functions ...................................................................................................... 75

Lambda Functions ................................................................................................................................. 76

Syntactic Variations............................................................................................................................... 77

Function Overloads ............................................................................................................................... 80

10. TYPESCRIPT ©¤ NUMBERS.................................................................................................... 82

Number Methods .................................................................................................................................. 85

toExponential() ..................................................................................................................................... 85

toFixed() ................................................................................................................................................ 86

iv

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download