Typescript Flashcards

1
Q

TypeScript

A

TypeScript extends JavaScript by adding types to the language.

TypeScript is an open-source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript and adds optional static typing to the language. TypeScript is designed for development of large applications and transcompiles to JavaScript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

TypeScript vs JavaScript

A

TypeScript = JavaScript + Types + other stuffs

Types: type checking, type definition,…

TypeScript is superset of JavaScript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why TypeScript?

A

Makes building these complex apps more manageable

Framework like angular 2 using it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why need Node.js in Typescript

A

Node.js compile Typescript to Javascript

Run Javascript on Node.js

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Typescript array

A
var myarr : number[];
myarr =[];
myarr=[1,2];
myarr.push(1);
myarr.push(''); // error
var a:number = myarr.pop();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If there is an error in TypeScript Compiler, will compiled js file be created?

A

Yes.

The error is only used for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

TypeScript vs JavaScript in action

A
  • Type restrict in TypeScript

- In JS, there is no restriction in function types or number of arguments but there is in TypeScript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

TypeScript function

A
  • Can use JS to define a function

- Restrict number of augments input and augment types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Optional augments in TypeScript function

A
function add (a, b, c=0) {
    return a + b + c;
}
function add (a, b, c?) {
    return a + b + c;
}
function add (a, b?, c) { // not valid
    return a + b + c;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Implicit typing

A
var a = 10; // TS automatically apply type number to a
var b = true; // TS automatically apply type boolean to a
var c = "Hello"; // TS automatically apply type string to a
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Implicit typing

A
var a = 10; // TS automatically apply type number to a
var b = true; // TS automatically apply type boolean to b
var c = "Hello"; // TS automatically apply type string to c
function greeting() : string {
    return "Hello";
}

var hello = greeting(); // TS automatically apply type string to hello

Notes:
- Has to be on the same line variable and assigned value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Type any in TS

A

var a;
var a: any;

a = 10;
a = true;
a = "String";

-> Use to migrate JS to TS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Union Type

A

var a : boolean | number;

a = 10;
a = true;
a = "String"; --> Error
How well did you know this?
1
Not at all
2
3
4
5
Perfectly