TypeScript ambient module

TypeScript ambient module: As we discussed in earlier tutorials TypeScript provides the facility to safely and easily use existing JavaScript libraries like jquery, angularjs, nodejs etc. Ambient declarations allow us to safely use existing popular JavaScript libraries. Ambient declaration files are saved with .d.ts extension. Syntax to declare ambient variables or modules: declare module ModuleName … Read more

TypeScript module

TypeScript module: A module refers to a set of standardized parts or independent units that can be used to construct a more complex structure. TypeScript modules provides a way to organize the code for better reuse. Syntax: export interface InterfaceName { //Block of statements } The import keyword is used to use the declared module … Read more

TypeScript namespaces

TypeScript NameSpace: TypeScript namespace is a way to organize your code. Internal modules in typescript are now referred to namespaces. The namespace keyword is used to define a namespace. Syntax: namespace NameSpaceName { export interface IInterfaceName { } export class ClassName { } } Access the class or interface in another namespace: NameSpaceName.ClassName; Example: namespace … Read more

Typescript duck typing

TypeScript duck typing: Duck-typing is a powerful feature which brings strong typing concepts in TypeScript code. TypeScript provides the duck typing type-checking which focus on the shape that values have. It checks for the presence of certain properties in the objects instead of the actual object type. The following example does not allow substitution of … Read more

Typescript object

TypeScript Object: A real world entity is known as an object. Like every real world object, software objects also have state and behavior. State of the object is represented by data members or fields and behavior is represented by methods. In TypeScript an object represents an instance which contains set of key value pairs. The … Read more

TypeScript abstract class

TypeScript Abstract Class: Abstract class is a way of implementing 0 to 10 Syntax: abstract class className { // declare fields // declare abstract/non-abstract methods } Abstract method: A method with no implementation i.e. without braces and followed by a semicolon. Syntax: abstract return_type methodName(); Example: abstract class Department { constructor(public name: string) { } … Read more

Typescript class

TypeScript Class: As we discussed in earlier tutorials that TypeScript supports object-oriented programming concepts like classes, interfaces, etc. Class acts as a blue print or template for creating objects. It provides state and behaviour for its objects. A class is used to encapsulate the data for the object. Syntax: class class_name { //field //constructor //function … Read more

typescript interface inheritance tutorial

Inheritance is one of the OOPs concepts which provides the facility to create a class (new class) from another class (existing class). Existing class is known as Parent/Super/Base class and new class is know as Child/Sub/Derived class. Child class will acquire the state and behavior of Parent class which can be modified or overridden by … Read more

Typescript interface

Dictionary meaning of interface: A point where two systems, subjects, organizations, etc., meet and interact. TypeScript interface: An interface is declared with interface keyword. It is a way of implementing 10 Syntax: interface interface_name { } Example: interface IPerson { firstName:string, lastName:string, sayHi: ()=>string } var customer:IPerson = { firstName:”Ajay”, lastName:”Laddha”, sayHi: ():string =>{return “Hi”} … Read more

TypeScript Union

TypeScript union type: TypeScript Union Type provides the facility to combine one or two types for a variable. The pipe symbol (|) is used to combine the two or more data types. Syntax: var varName: dataType1|dataType2|dataType3 Example: function unionTest(value:string|number):void{ console.log(value); } unionTest(“Jai”); unionTest(123);