Typescript

Understanding Nullable Types in Typescript with examples

Typescript
Understanding Nullable Types in Typescript with examples: Nullable type is introduced in typescript 2.0, this helps us to keep initialized objects to have some values other than null all the time.   Default number | Assigning null: For eg: let home2OfficeKm = 10; home2OfficeKm = null;     Works fine in typescript 2.0 earlier versions, if you do not want null to be assigned to the home2OfficeKm anytime then you can add the below entry in your tsconfig.json file   tsconfig.json: // add this with your existing compilerOptions properties in the tsconfig.json file compilerOptions{ "strictNullChecks":true }   then the above snippet throws the "Type null is not assignable to type number" error.   But same thing won't hap...

Difference between Javascript and Typescript

Javascript, Typescript
Difference between Javascript and Typescript: Javascript Typescript var myVar = 'hello'; myVar = 10; console.log(myVar); // prints 10 let myVar = 'hello'; myVar = 10; console.log(myVar) // we get the error here stating //Type 'number' is not assignable to type 'string' We dont have a type number only in javascript. Typescript does not have float/double types, everything is considered as type number only (like 10, 11.2, 27.8000). As types are not supported in javascript, explicit assignments will also be not possible. Explicit assignment is possible let name:string = 'javadomain'; let price:number = 100000; We dont have any types like any, and also it even does not maintain the types internally based on the initialization assignments we can have the ...

Typescript Hello world in local system Example

Typescript
Step 1: Install Typescript in Your Local Machine Install typescript in your local machine to compile and test typescript. Instructions / steps to install typescript can be found in the below link We need typescript in local,because typescript is not like javascript which can directly run on the browser. It has to be converted to javascript before running in any browser. This is because all browsers are currently supporting ES5 only and typescript is ES6, so typescript compiler converts typescript (ES6) file to javascript (ES5) file internally to make it runnable in the browsers. So we need typescript to be installed on our local machine to compile and convert the typescript to javascript before running it on browsers. How to install typescript in windows 10?   Step 2: C...

How to install typescript in windows 10?

Typescript
How to install typescript in windows 10? Ensure you have already node package manager(npm) installed on your machine if this is not installed then follow the below link to get it installed, http://www.ngdeveloper.com/install-node-js-windows-10/   We should definitely have npm package manager installed on our machine, once you installed npm you can verify with npm -version command and start installing the typescript.     Run the below command to install typescript in your machine, npm -g install typescript

Typescript Quick Notes for Angular Developers

Angular, Articles, Javascript, Typescript
Typescript Quick Notes for Angular Developers: As because of angular's reach angular developers are forced to learn typescript. It is not tough but it is better to know the below basic syntax to code faster.   1. Converting array to JSON in typescript   [html] selectedItems = []; JSON.stringify(this.selectedItems); [/html]       2. For loop in typescript   [html] for(let item of items){ console.log(item.itemName) } [/html]   items is an array/collection of item.     3. String concatenation in typescript   [html] appendTxtTemp:string = 'Hello'; this.appendTxtTemp = this.appendTxtTemp.concat(" ") .concat('World'); // prints Hello World [/html]     4. S...