Debug TypeScript with Visual Studio Code

Debug TypeScript with Visual Studio Code

Before Starting Please setup a very simple TypeScript Project. Create a Folder Project1 Create a folder Project1 and open in Visual Studio Code. Create Page Index.html <html> <body> <h1>Hello World <h1> </body> <scripttype=”text/javascript”src=”JS/test.js”></script> </html> Create Configuration File tsconfig.json { “compilerOptions”: { /* Basic Options */ /* Specify ECMAScript target version: ‘ES3’ (default), ‘ES5′,’ES2015’, ‘ES2016’, ‘ES2017’, or ‘ESNEXT’. */ “target”: “es5”, /* Specify module code generation: […]

Read More Leave comment

TypeScript Namespaces and Modules

TypeScript Namespaces and Modules

Using Namespaces Namespaces are simply named JavaScript objects in the global namespace.They can span multiple files, and can be concatenated using –outFile. Namespaces can be a good way to structure your code in a Web Application, with all dependencies included as <script> tags in your HTML page. namespace Validation { export interface StringValidator { isAcceptable(s: string): boolean; } const lettersRegexp = /^[A-Za-z]+$/; const numberRegexp = […]

Read More Leave comment

TypeScript Advanced Types

TypeScript Advanced Types

Intersection Types An intersection type combines multiple types into one. This allows you to add together existing types to get a single type that has all the features you need. interface IStudent { id: string; age: number; } interface ICompany { companyId: string; } type A = IStudent & ICompany; let x: A; x.age = 5; x.companyId = ‘CID5241’; x.id = ‘ID3241’; Union Type We can […]

Read More Leave comment

TypeScript Generics

TypeScript Generics

With generics, TypeScript enables you to write code that can act on a variety of data types instead of being limited to a single one. function identity<T>(arg: T): T { return arg; } The Need for Generics function randomIntElem(theArray: number[]): number { let randomIndex = Math.floor(Math.random()*theArray.length); return theArray[randomIndex]; } let positions: number[] = [103, 458, 472, 458]; let randomPosition: number = randomIntElem(positions); Once we have […]

Read More Leave comment

TypeScript Interfaces

TypeScript Interfaces

Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members. It often helps in providing a standard structure that the deriving classes would follow. TypeScript helps us keep a contract with our vales by allowing us to define fine-grained type checking for […]

Read More Leave comment

TypeScript Classes

TypeScript Classes

JavaScript uses functions and prototype-based inheritance to build up reusable components, but this may feel a bit awkward to programmers more comfortable with an object-oriented approach, where classes inherit functionality and objects are built from these classes. Classes class Greeter { greeting: string; constructor(message: string) { this.greeting = message; } greet() { return “Hello, ” + this.greeting; } } let greeter = new Greeter(“world!”); We […]

Read More Leave comment

Functions

Functions

Functions are the fundamental building block of any applications in JavaScript. TypeScript functions can be created both as a named function or as an anonymous function. // Named function function sum(x, y) { return x + y; } // Anonymous function let sum= function(x, y) { return x + y; }; TypeScript Function function sum(x: number, y: number): number { return x + y; } […]

Read More Leave comment

Variable Declarations

Variable Declarations

let and const are two relatively new types of variable declarations in JavaScript. var declarations Declaring a variable in JavaScript has always traditionally been done with the var keyword. function f() { var message = “Hello, world!”; return message; } var-scoping or function-scoping function f(input: boolean) { var a = 100; if (input) { // Still okay to reference ‘a’ var b = a + […]

Read More Leave comment

TypeScript Basic Data Types

TypeScript Basic Data Types

Boolean The most basic datatype is the simple true/false value, which JavaScript and TypeScript call a boolean value. let isDone: boolean = false; Example function f() { let message : boolean = true; return message; } Number As in JavaScript, all numbers in TypeScript are floating point values. These floating point numbers get the type number. let decimal: number = 6; let hex: number = […]

Read More Leave comment

Set up Visual Studio Code

Set up Visual Studio Code

We will continue with our previous example , but this we won’t compile manually.This VS code will do for us. SetUp Create TypeScript Project.We will fire the command and TypeScript compiler will create the project for us. tsc –init After firing the command you can see tsc generates a new file “tsconfig.json” It will consist of default compiler option.Here we can mention our default js […]

Read More Leave comment
Visitors
Page Hits: 53199
Unique Visitors :
13184
Made With By Keshab