TypeScript Interview Questions and Answers

30+ TOP TypeScript Interview Questions and Answers

TypeScript Interview Questions
TypeScript Interview Questions

1) What is TypeScript?
TypeScript is an object-oriented and compiled language.
TypeScript is also known as a set of tools.
TypeScript is used for application-scale development.

2) What are the features of TypeScript?
Features of TypeScript are:
TypeScript is just same as JavaScript
Supports other JS libraries
It is portable
Here, .js file can be renamed to .ts

3) Who is the inventor of TypeScript?
Designed by Anders Hejlsberg at Microsoft.

4) What are the benefits of TypeScript?
Benefits of TypeScript are:

Compilation
Strong Static Typing
supports type definitions
supports Object Oriented Programming

5) What are the components of TypeScript?
There are three components of TypeScript are:
TypeScript Language
TypeScript Compiler
TypeScript Language Service

6) What are the types of comment in TypeScript?
There are two types of comment in TypeScript:

Single line.
Example: // Single Line Comment.

Multiple line.
Example: /* Multiple Line Comment.*/

7) What is the extension supported by TypeScript?
TypeScript supports .ts extension.

8) What is negation operator?
It is a type of miscellaneous Operator and used to Change the sign of a value.

It is denoted by “-” symbol.

9) How to call base class constructor from child class in TypeScript?
By using super().

10) What is the Default Access Modifier for members of a class in TypeScript?
public is the default access modifier for members of a class.

11) Does TypeScript support function overloading?
Yes, Typescript support function overloading.

12) How to generate TypeScript definition File from .ts file?
By using tsc compiler, you can generate TypeScript definition file from .ts file.

13) What are Modules in Typescript?
Modules helps in organizing the code written in TypeScript.

Two types of Modules are:
Internal Modules
External Modules

14) Is it possible to combine multiple .ts files into a single .js file?
yes, It is possible.

15) What is the syntax to declare ambient variables in TypeScript?
The syntax to declare ambient variables:

declare module Module_Name {
declare module Module_Name {
}

16) What is Internal Module in TypeScript?
Internal Module: It is used to logically group classes, interfaces, functions into one unit and can be exported in another module.

17) What is the syntax to declare External Module using export in TypeScript?
The syntax to declare External Module using export is:

//FileName:TutorialandExample.ts
export interface TutorialandExample {
//code declarations
}

18) What is the syntax to declare External Module using import in TypeScript?
The syntax to declare External Module using import is:

import TutorialandExampleRef = require(“./TutorialandExample”);

19) What is the syntax to declare Internal Module in TypeScript?
What is the syntax to declare Internal Module in TypeScript?

module TutorialandExample {
export function add(x, y) {
console.log(x+y);
}
}

20) What is Nested Namespaces in TypeScript?
Nested Namespaces: we can define one namespace inside another namespace.

21) What is the syntax to declare Nested Namespace in TypeScript?
The syntax to declare Nested Namespace is:

namespace firstnamespace {
export namespace secondnamespace {
export class classname { }
}
}

22) What is Object in TypeScript?
Object: It is an instance of class which contains set of key and value pairs.

Here, the values can be scalar values/functions or array of other objects.

23) What is Duck-typing in TypeScript?
Duck-typing: It is used to verify the presence of certain properties in the objects to check their suitability.

Here, two objects are considered to be of the same type if both share the same set of properties.

24) What is the use of this keyword in TypeScript?
this keyword: It refers to the current instance of the class. In this keyword, the parameter name and the name of the class field are the same.

25) What is the use of new keyword?
new keyword: It is used for instantiation in object creation.

26) What are the types of inheritance classified in TypeScript?
The types of inheritance classified in TypeScript are:
Single
Multiple
Multilevel

27) What are the types of access modifiers supported by TypeScript?
The types of access modifiers supported by TypeScript are:
Public
Private
Protected

28) What is the use of pipe symbol in TypeScript?
pipe symbol: It is used to combine two or more data types to denote a Union Type.

29) What is the use of push() and pop() method in Tuple?
push() method: It appends an item to the tuple.
pop() method: This method removes and returns the last value in the tuple.

30) What are the variable scopes available in TypeScript?
The variable scopes available in TypeScript are:
Global Scope
Class Scope
Local Scope

Real Time TypeScript Interview Questions