Google News
logo
TypeScript Interview Questions
TypeScript is a free and open-source programming language developed and maintained by Microsoft. It is a strongly typed superset of JavaScript that compiles to plain JavaScript. It is a language for application-scale JavaScript development. TypeScript is quite easy to learn and use for developers familiar with C#, Java and all strong typed languages.
 
TypeScript can be executed on Any browser, Any Host, and Any Operating System. TypeScript is not directly run on the browser. It needs a compiler to compile and generate in JavaScript file. TypeScript is the ES6 version of JavaScript with some additional features.

Syntax :
var message:string = "Welcome to Free Time Learning"
console.log(message)
A TypeScript code is written in a file with .ts extension and then compiled into JavaScript using the compiler. You can write the file in any code editor and the compiler needs to be installed on your platform. After the installation, the command tsc <filename>.ts compiles the TypeScript code into a plain JavaScript file.
 
SN JavaScript TypeScript
1 It was developed by Netscape in 1995. It was developed by Anders Hejlsberg in 2012.
2 JavaScript source file is in ".js" extension. TypeScript source file is in ".ts" extension.
3 JavaScript doesn't support ES6. TypeScript supports ES6.
4 It doesn't support strongly typed or static typing. It supports strongly typed or static typing feature.
5 It is just a scripting language. It supports object-oriented programming concept like classes, interfaces, inheritance, generics, etc.
6 JavaScript has no optional parameter feature. TypeScript has optional parameter feature.
7 It is interpreted language that's why it highlighted the errors at runtime. It compiles the code and highlighted errors during the development time.
8 JavaScript doesn't support modules. TypeScript gives support for modules.
9 In this, number, string are the objects. In this, number, string are the interface.
10 JavaScript doesn't support generics. TypeScript supports generics.
There are different reasons why a JavaScript developer should consider using TypeScript. Some of them include :
 
Using new features of ECMAScript : TypeScript supports new ECMAScript standards and transpile them to ECMAScript targets of your choice. So, you can use features of ES2015 and beyond.
 
Static Typing : JavaScript is dynamically typed and does not know what type a variable is until it is actually instantiated at run-time. TypeScript adds type support to JavaScript.
 
Type Inference : TypeScript makes typing a bit easier and a lot less explicit by the usage of type inference. Even if you don’t explicitly type the types, they are still there to save you from doing something which otherwise would result in a run-time error.
 
Better IDE Support : The development experience with TypeScript is a great improvement over JavaScript. There is a wide range of IDEs that have excellent support for TypeScript, like Visual Studio & VS code, Atom, Sublime, and IntelliJ/WebStorm.
 
Strict Null Checking : Errors, like cannot read property ‘x’ of undefined, is common in JavaScript programming. You can avoid most of these kinds of errors since one cannot use a variable that is not known to the TypeScript compiler.
 
Interoperability : TypeScript is closely related to JavaScript so it has great interoperability capabilities, but some extra work is required to work with JavaScript libraries in TypeScript.
Cross-Platform :  The TypeScript compiler can be installed on any Operating System such as Windows, MacOS, and Linux.
 
Object-Oriented Language : TypeScript provides features like Classes, Interfaces, and Modules. Thus, it can write object-oriented code for client-side as well as server-side development.
 
Static Type-Checking : TypeScript uses static typing and helps type checking at compile time. Thus, you can find errors while writing the code without running the script.
 
Optional Static Typing : TypeScript also allows optional static typing in case you are using the dynamic typing of JavaScript.
 
DOM Manipulation : You can use TypeScript to manipulate the DOM for adding or removing elements.
 
ES 6 Features : TypeScript includes most features of planned ECMAScript 2015 (ES 6, 7) such as class, interface, Arrow functions, etc.
TypeScript has the following benefits.
 
* It provides the benefits of optional static typing. Here, Typescript provides types that can be added to variables, functions, properties, etc.
* Typescript has the ability to compile down to a version of JavaScript that runs on all browsers.
* TypeScript always highlights errors at compilation time during the time of development whereas JavaScript points out errors at the runtime.
* TypeScript supports strongly typed or static typing whereas this is not in JavaScript.
* It helps in code structuring.
* It uses class-based object-oriented programming.
* It provides excellent tooling supports with IntelliSense which provides active hints as the code is added.
* It has a namespace concept by defining a module.
TypeScript has the following disadvantages :
 
* TypeScript takes a long time to compile the code.
* TypeScript does not support abstract classes.
* If we run the TypeScript application in the browser, a compilation step is required to transform TypeScript into JavaScript.
* Web developers are using JavaScript from decades and TypeScript doesn?t bring anything new.
* To use any third party library, the definition file is must. And not all the third party library have definition file available.
* Quality of type definition files is a concern.
TypeScript has three primitive types that are frequently used : string, number, and boolean. These correspond to the similarly named types in JavaScript. 
 
* string : represents text values such as “javascript”, “typescript”, etc.
* number : represents numeric values like 1, 2, 32, 43, etc,.
* boolean : represents a variable that can have either a ‘true’ or ‘false’ value.
There are three different types of components in TypeScript which includes :
 
Language : It comprises of the syntax, keywords, and type annotations.
 
The TypeScript Compiler : This compiler (tsc) converts the instructions written in TypeScript to its JavaScript equivalent.
 
The TypeScript Language Service : The Language Service exposes an additional layer around the core compiler pipeline, editor-like applications. The language service supports the common set of typical editor operations.
TypeScript can be installed and managed with the help of node via npm (the Node.js package manager). To install TypeScript, first ensure that the npm is installed correctly, then run the following command which installs TypeScript globally on the system.
$ npm install -g typescript  
It installs a command line code "tsc" which will further be used to compile our Typescript code. Make sure that we check the version of Typescript installed on the system.
 
Following steps are involved for installing TypeScript :
 
* Download and run the .msi installer for the node.
* Enter the command "node -v" to check if the installation was successful.
* Type the following command in the terminal window to install Typescript : $ npm install -g typescript
The extension for any TypeScript file is .ts. And any JavaScript file is a TypeScript file as it is a superset of JavaScript. So, once you change the extension of “.js” to “.ts”, your TypeScript file is ready. To compile any .ts file into .js use the following command :
 
tsc <TypeScript File Name>
 
For example, to compile “freetimelearn.ts
 
tsc freetimelearn.ts
 
And the result would be freetimelearn.js
Yes, we can combine multiple files. While compiling, we need to add –outFILE [OutputJSFileName] option.
 
tsc -- outFile comman.js file1.ts file2.ts file3.ts
 
This will compile all 3 “.ts” file and output into a single “comman.js” file.
 
tsc --outFile file1.ts file2.ts file3.ts
 
If you don’t provide an output file name, file2.ts and file3.ts will be compiled and the output will be placed in file1.ts. So now your file1.ts contains JavaScript code.
The Type System represents the different types of values supported by the language. It checks the validity of the supplied values before they are stored or manipulated by the program.
 
It can be classified into two types such as :
 
Built-in : This includes number, string, boolean, void, null and undefined.
User-defined : It includes Enumerations (enums), classes, interfaces, arrays, and tuple.
The built-in data types are also known as primitive data types in Typescript. These are given below.
 
Number type : It is used to represent number type values. All the numbers in TypeScript are stored as floating point values.
Syntax : let identifier: number = value;
 
String type : It represents a sequence of characters stored as Unicode UTF-16 code. We include string literals in our scripts by enclosing them in single or double quotation marks.
Syntax : let identifier: string = " ";
 
Boolean type : It is used to represent a logical value. When we use the Boolean type, we get output only in true or false. A Boolean value is a truth value that specifies whether the condition is true or not.
Syntax : let identifier: bool = Boolean value;
 
Null type : Null represents a variable whose value is undefined. It is not possible to directly reference the null type value itself. Null type is not useful because we can only assign a null value to it.
Syntax : let num: number = null;
 
Undefined type : It is the type of undefined literal. The Undefined type denotes all uninitialized variables. It is not useful because we can only assign an undefined value to it. This type of built-in type is the sub-type of all the types.
Syntax : let num: number = undefined;
 
Void type : A void is the return type of the functions that do not return any type of value. It is used where no datatype is available.
Syntax : let unusable: void = undefined;
A variable is a named space in the memory which is used to store values. The type syntax for declaring a variable in TypeScript includes a colon (:) after the variable name, followed by its type. Similar to JavaScript, we use the var keyword to declare a variable. While declaring a variable in Typescript, certain rules must be followed-
 
* The variable name must be an alphabet or numeric digits.
* You cannot start the name with digits.
* It cannot contain spaces and special characters, except the underscore(_) and the dollar($) sign.
There are four ways of declaring a variable :
var [identifier] : [type-annotation] = value; //Declaring type and value in a single statement

var [identifier] : [type-annotation]; //Declaring type without value

var [identifier] = value; //Declaring its value without type

var [identifier]; //Declaring without value and type
We use arrays to store values of the same type. Arrays are ordered and indexed collections of values. The indexing starts at 0, i.e., the first element has index 0, the second has index 1, and so on.
 
Here is the syntax to declare and initialize an array in TypeScript.
let values: number[] = [];
values[0] = 10;
values[1] = 20;
values[2] = 30;
You can also create an array using the short-hand syntax as follows :
let values: number[] = [15, 20, 25, 30];
TypeScript provides an alternate syntax to specify the Array type.
let values: Array<number> = [15, 20, 25, 30];
There are times when you want to store a value in a variable but don’t know the type of that variable in advance. For example, the value is coming from an API call or the user input. The ‘any’ type allows you to assign a value of any type to the variable of type any.
let person: any = "Foo";
Here is an example that demonstrates the usage of any type.
// json may come from a third-party API
const employeeData: string = `{"name": "Ramana", "salary": 90000}`;

// parse JSON to build employee object
const employee: any = JSON.parse(employeeData);

console.log(employee.name);
console.log(employee.salary);
TypeScript assumes a variable is of type any when you don’t explicitly provide the type, and the compiler cannot infer the type from the surrounding context. 
The void indicates the absence of type on a variable. It acts as the opposite type to any. It is especially useful in functions that don’t return a value.
function notify(): void {
  alert("The user has been notified.");
}
If a variable is of type void, you can only assign the null or undefined values to that variable.
TypeScript supports the following object-oriented terms :
 
* Modules
* Classes
* Interfaces
* Inheritance
* Data Types
* Member functions
The interface is a structure that defines the contract in your application. It defines the syntax for classes to follow. It contains only the declaration of the members and it is the responsibility of the deriving class to define the members. The TypeScript compiler uses interface for type-checking and checks whether the object has a specific structure or not.
 
Syntax :
interface interface_name {
// variables' declaration
// methods' declaration
}
We know, TypeScript is a type of Object-Oriented JavaScript language and supports OOPs programming features like classes, interfaces, etc. Like Java, classes are the fundamental entities which are used to create reusable components. It is a group of objects which have common properties. A class is a template or blueprint for creating objects. It is a logical entity. The "class" keyword is used to declare a class in Typescript.
 
Example :
class Student {    
    studCode: number;    
    studName: string;    
    constructor(code: number, name: string) {    
            this.studName = name;    
            this.studCode = code;    
    }    
    getGrade() : string {    
        return "A+" ;    
    }    
}​
    
Features of a class are :
 
* Inheritance
* Encapsulation
* Polymorphism
* Abstraction
 The access modifiers supported by TypeScript are :
 
Protected : All child classes and members have access to them, but the instance does not.
Private : Only members have access
Public : Members, child classes, and instances of the class have access to the public modifier.
A loop statement allows to repeat the execution of a statement or a series of statements. To handle looping requirements, TypeScript provides a variety of loops.
 
* For Loop : The for loop is a definite loop implementation. A definite loop is defined as a loop with a fixed number of iterations.
 
* While Loop : When the condition supplied evaluates to true, the while loop executes the instructions.
 
* Do..While Loop : The do...while loop is identical to the while loop, except that the condition isn't evaluated the first time the loop runs.
When one side of the equation has type but the other does not, the TypeScript compiler determines the form. You can skip typing on the right side because TypeScript will figure it out for you. This reduces the amount of time spent typing code.
Static typing refers to a compiler that has recognisable variables, arguments, and object members at compile time. This aids in the early detection of faults.
* Import keyword is used to export declaration. Example: export * from module
* Any variable, function, or type alias can be exported with the export keyword
By combining TypeScript with Node.js, backend applications can benefit from the added security that the language provides.
if(value) return true if value is not null, undefined, empty, false, 0 or NaN.
A module is a powerful way to create a group of related variables, functions, classes, and interfaces, etc. It can be executed within their own scope, not in the global scope. In other words, the variables, functions, classes, and interfaces declared in a module cannot be accessible outside the module directly.
 
Creating a Module
 
A module can be created by using the export keyword and can be used in other modules by using the import keyword.
module module_name{  
    class xyz{  
        export sum(x, y){  
            return x+y;  
         }  
    } ​
We can divide the module into two categories :
 
* Internal Module
* External Module
 
Internal Module : Internal modules were in the earlier version of Typescript. It was used for logical grouping of the classes, interfaces, functions, variables into a single unit and can be exported in another module. The modules are named as a namespace in the latest version of TypeScript. So today, internal modules are obsolete. But they are still supported by using namespace over internal modules.
 
Syntax :
module Sum {   
   export function add(a, b) {    
      console.log("Sum: " +(a+b));   
   }   
} ​

 

External Module : External modules are also known as a module. When the applications consisting of hundreds of files, then it is almost impossible to handle these files without a modular approach. External Module is used to specify the load dependencies between the multiple external js files. If the application has only one js file, the external module is not relevant. ECMAScript 2015(ES6) module system treats every file as a module.

Syntax :
export class MyClass {
}
export var x:MyClass instance = new MyClass();
Namespace groups functionalities logically. These maintain the legacy code of typescript internally. It encapsulates the features and objects that share certain relationships. A namespace is also known as internal modules. A namespace can also include interfaces, classes, functions, and variables to support a group of related functionalities.
 
Syntax :
namespace <namespace_name> {
export interface I1 { }
export class c1{ }
The unknown type is the type-safe counterpart of any type. You can assign anything to the unknown, but the unknown isn’t assignable to anything but itself and any, without performing a type assertion of a control-flow-based narrowing. You cannot perform any operations on a variable of an unknown type without first asserting or narrowing it to a more specific type.
 
Consider the following example. We create the foo variable of unknown type and assign a string value to it. If we try to assign that unknown variable to a string variable bar, the compiler gives an error.
let foo: unknown = "Chanti";
let bar: string = foo; // Type 'unknown' is not assignable to type 'string'.(2322)
You can narrow down a variable of an unknown type to something specific by doing typeof checks or comparison checks or using type guards. For example, we can get rid of the above error by
let foo: unknown = "Chanti";
let bar: string = foo as string;
Objects are dictionary-like collections of keys and values. The keys have to be unique. They are similar to arrays and are also sometimes called associative arrays. However, an array uses numbers to index the values, whereas an object allows you to use any other type as the key.
 
In TypeScript, an Object type refers to any value with properties. It can be defined by simply listing the properties and their types. For example,
let pt: { x: number; y: number } = {
  x: 10,
  y: 20
};
An object type can have zero or more optional properties by adding a ‘?’ after the property name. 
let pt: { x: number; y: number; z?: number } = {
  x: 10,
  y: 20
};
console.log(pt);
In the example above, because the property ‘z’ is marked as optional, the compiler won’t complain if we don’t provide it during the initialization.
When a variable is declared without initialization, it’s assigned the undefined value. It’s not very useful on its own. A variable is undefined if it’s declared, but no value has been assigned to it. In contrast, null is assigned to a variable, and it represents no value. 
console.log(null == null); // true
console.log(undefined == undefined); // true
console.log(null == undefined); // true, with type-conversion
console.log(null === undefined); // false, without type-conversion
console.log(0 == undefined); // false
console.log('' == undefined); // false
console.log(false == undefined); // false
Enums allow us to create named constants. It is a simple way to give more friendly names to numeric constant values. An enum is defined by the keyword enum, followed by its name and the members.
 
Consider the following example that defines an enum Team with four values in it.
enum Team {
Alpha,
Beta,
Gamma,
Delta
}
let t: Team = Team.Delta;

 

By default, the enums start the numbering at 0. You can override the default numbering by explicitly assigning the values to its members.
 
TypeScript also lets you create enums with string values as follows :
enum Author {
  Anders = "Anders",
  Hejlsberg = "Hejlsberg"
};
Similar to JavaScript, the typeof operator in TypeScript returns the type of the operand as a string.
console.log(typeof 10);  // "number"
console.log(typeof 'foo');  // "string"
console.log(typeof false);  // "boolean"
console.log(typeof bar);  // "undefined"
In TypeScript, you can use the typeof operator in a type context to refer to the type of a property or a variable.
let greeting = "hello";
let typeOfGreeting: typeof greeting;  // similar to let typeOfGreeting: string 
A rest parameter allows a function to accept an indefinite number of arguments as an array. It is denoted by the ‘’ syntax and indicates that the function can accept one or more arguments.
function add(...values: number[]) {
let sum = 0;
values.forEach(val => sum += val);
return sum;
}
const sum = add(5, 10, 15, 20);
console.log(sum);  // 50
In contrast, the rest arguments allow a function caller to provide a variable number of arguments from an array. Consider the following example.
const first = [1, 2, 3];
const second = [4, 5, 6];

first.push(...second);
console.log(first);  // [1, 2, 3, 4, 5, 6] 
Parameter destructing allows a function to unpack the object provided as an argument into one or more local variables.
function multiply({ a, b, c }: { a: number; b: number; c: number }) {
console.log(a * b * c);
}

multiply({ a: 1, b: 2, c: 3 });

You can simplify the above code by using an interface or a named type, as follows:
type ABC = { a: number; b: number; c: number };

function multiply({ a, b, c }: ABC) {
console.log(a * b * c);
}

multiply({ a: 1, b: 2, c: 3 });
A tsconfig.json file in a directory marks that directory as the root of a TypeScript project. It provides the compiler options to compile the project.
 
Here is a sample tsconfig.json file :
{
 "compilerOptions": {
   "module": "system",
   "noImplicitAny": true,
   "removeComments": true,
   "outFile": "../../built/local/tsc.js",
   "sourceMap": true
 },
 "include": ["src/**/*"],
 "exclude": ["node_modules", "**/*.spec.ts"]
}
TypeScript Generics is a tool that provides a way of creating reusable components. It is able to create components that can work with a variety of data types rather than a single data type. Also, it provides type safety without compromising the performance, or productivity. Generics allow us to create generic classes, generic functions, generic methods, and generic interfaces.
 
In generics, a type parameter is written between the open (<) and close (>) brackets which makes it strongly typed collections. It uses a special kind of type variable <T> that denotes types.
 
Example :
function identity<T>(arg: T): T {
return arg;
}
let output1 = identity<string>("edureka");
let output2 = identity<number>( 117 );
console.log(output1);
console.log(output2);
TypeScript Map file is a source map file that holds information about our original files. The .map files are source map files that let tools map between the emitted JavaScript code and the TypeScript source files that created it. Also, debuggers can consume these files so we can debug the TypeScript file instead of the JavaScript file.
Type assertion works like a typecasting in other languages, but it doesn’t perform type checking or restructuring of data in other languages like C# and Java. The typecasting comes with runtime support whereas type assertion has no impact on runtime. However, type assertions are used purely by the compiler and provide hints to the compiler on how we want our code to be analyzed.
 
Example :
let empCode: any = 007;
let employeeCode = <number> code;
console.log(typeof(employeeCode)); //Output: number
The rest parameter is used to pass zero or more values to a function. It is declared by prefixing the three-dot characters (‘’)before the parameter. It allows the functions to have a variable number of arguments without using the arguments object. It is very useful where we have an undetermined number of parameters.
Rules to follow in rest parameter :
 
* Only one rest parameter is allowed in a function.
* It must be an array type.
* It must be a last parameter in the parameter list.

Example :
function sum(a: number, ...b: number[]): number {
let result = a;
for (var i = 0; i < b.length; i++) {
result += b[i];
}
console.log(result);
}
let result1 = sum(2, 4);
let result2 = sum(2,4,6,8);
Yes, TypeScript support all object-oriented principles. There are four main principles to object-oriented programming :
 
* Encapsulation,
* Inheritance,
* Abstraction, and
* Polymorphism.
By using a juggling-check, we can check both null and undefined :
if (x == null) {  
} ​
 If we use a strict-check, it will always true for values set to null and won't evaluate as true for undefined variables.
 
Example :
var a: number;  
var b: number = null;  
function check(x, name) {  
    if (x == null) {  
        console.log(name + ' == null');  
    }  
    if (x === null) {  
        console.log(name + ' === null');  
    }  
    if (typeof x === 'undefined') {  
        console.log(name + ' is undefined');  
    }  
}  
check(a, 'a');  
check(b, 'b');​
Output :
"a == null"  
"a is undefined"  
"b == null"  
"b === null"  
The as is the additional syntax for Type assertion in TypeScript. The reason for introducing the as-syntax is that the original syntax (<type>) conflicted with JSX.
 
Example :
let empCode: any = 111;     
let employeeCode = code as number;​
When using TypeScript with JSX, only as-style assertions are allowed.
An anonymous function is a function that is declared without any named identifier. These functions are dynamically declared at runtime. Also, anonymous functions can accept inputs and return outputs, just as standard functions do. It is usually not accessible after its initial creation.
 
Example :
let myAdd = function(x: number, y: number): number { 
return a+b; 
}; 
console.log(myAdd())
If subclass (child class) has the same method as declared in the parent class, it is known as method overriding. In other words, redefined the base class methods in the derived class or child class.
 
Rules for Method Overriding
 
* The method must have the same name as in the parent class
* The method must have the same parameter as in the parent class.
* There must be an IS-A relationship (inheritance).

Example :
class NewPrinter extends Printer {  
    doPrint(): any {  
        super.doPrint();  
        console.log("Called Child class.");  
    }  
    doInkJetPrint(): any {  
        console.log("Called doInkJetPrint().");  
    }  
}  
let printer: new () => NewPrinter;  
printer.doPrint();  
printer.doInkJetPrint(); 
Tuples are a collection of values that are diverse. It allows for the storage of many fields of various sorts. Tuples can also be used as function parameters.
 
There are instances when it is necessary to save a collection of values of various types. Arrays will not suffice in this situation. TypeScript provides a data type called tuple that aids in this endeavor.
 
Syntax :
var tuple_name = [value c,value b,value c,…value n]
For Example :
var yourtuple = [12,"Hi"];
Combining simpler partial classes is a popular approach of constructing classes from reusable components. For languages like Scala, you may be familiar with the concept of mixins or characteristics.
 
To extend a base class, the design relies on generics and class inheritance. The finest mixin support in TypeScript is provided through the class expression pattern.
 
We have a class where mixins are applied on top of it.
class Sprite {
 name = "";
 x = 0;
 y = 0;
 constructor(name: string) {
   this.name = name;
 }
}
Based on a condition given as a type relationship test, a conditional type chooses one of two alternative types :
 
T extends U ? X : Y
 
When T can be assigned to U, the type is X, and when it can't, the type is Y.
 
Because the condition depends on one or more type variables, a conditional type T extends U? X: Y and is either resolved to X or Y or delayed. Whether to resolve to X or Y, or to defer, when T or U contains type variables is determined by whether the type system has enough information to conclude that T is always assignable to U.
Distributive conditional types are conditional types in which the checked type is a bare type parameter. During instantiation, distributive conditional types are automatically distributed over union types.
 
For example, an instantiation of T extends U ? X : Y with the type argument A | B | C for T is resolved as (A extends U ? X : Y) | (B extends U ? X : Y) | (C extends U ? X : Y).
In TypeScript, both Interface and Type describe the structure of objects. The following table explains the differences between both of them :

Interface  Type
It’s a form of syntax. It’s a form of a collection of data types.
Provides a way to define the entities. It supports the creation of a new name for a type.
Comparatively includes more capabilities than Type. Comparatively includes fewer capabilities than Interface.
Can use multiple merged declarations Cannot use multiple merged declarations
Two interfaces having the same name get merged. Two interfaces having the same name get merged.
TypeScript allows us to use more than one data type for a variable or a function parameter, and this concept is called union type. A union type enables us to define a variable with multiple types using the pipe ('|') symbol.
 
Syntax :
(type1 | type2 | type3 | .. | typeN)
Example, 
let myVar : string | number; //Variable with union type declaration
 
myVar = 256; //OK
myVar = 'Maddy'; //OK
 
myVar = true; //Error - boolean not allowed
Here, the myVar variable can hold both string and number, allowing flexibility to use both data types.
You can resolve module imports differently based on whether the module reference is relative or non-relative.
 
A relative import starts with /, ./ or ../. 
 
Example, 
import Entry from "./components/Entry";
import { DefaultHeaders } from "../constants/http";
* Any other import is considered non-relative.

Example, 
import * as $ from "jquery";
import { Component } from "@angular/core";
 
* You can use relative imports for our modules that are guaranteed to manage their relative location at runtime.
* You can resolve non-relative imports through path mapping or relative to baseUrl.
A Triple-Slash Directive is a single-line comment that contains a single XML tag. You can use the content of the comment as a compiler directive.
 
They are only valid at the top of their containing file. A triple-slash directive can be preceded only by single or multi-line comments, including other triple-slash directives. Below listed are some of the triple-slash directives in TypeScript :
/// <reference path="..." />
This directive allows a file to include an existing built-in lib file explicitly.
/// <reference no-default-lib="true"/>
This directive marks a file as a default library.
ES6 version of TypeScript provides shorthand syntax for defining the anonymous function, i.e., for function expressions. These arrow functions are also called Lambda functions. A lambda function is a function without a name. Arrow function omits the function keyword.
 
Example :
let sum = (a: number, b: number): number => {    
            return a + b;    
}  
console.log(sum(20, 30)); //returns 50    
In the above, the ?=>? is a lambda operator and (a + b) is the body of the function and (a: number, b: number) are inline parameters.
Advertisement