Top 10 TypeScript Interview Questions and Answers 2024

Last Updated on by in Web Development

Typescript interview questions 2019

Typescript interview questions 2021 are what we are going to explore in this article. Microsoft has developed typescript. It is an open source language. One can say that TypeScript is the subset of JavaScript. We use TypeScript when we are to develop large applications.We rely on TypeScript in case we are to build JavaScript applications on both server and client side.

Even though we identify TypeScript as a programming language, there is nothing wrong in considering it as a toolset as well. TypeScript is portable, and it supports several JavaScript libraries. Here in this article, we are going to look at Typescript interview questions one might encounter.

Are you looking for a job which requires you to do TypeScript programming?

Well, you need to get familiar with the TypeScript interview questions then. As far as interviews are concerned, every interview can be a unique experience. Nonetheless, you need to have precise knowledge about TypeScript to surpass the Typescript interview questions.

We have come up with the most crucial interview Typescript interview questions regarding TypeScript. We hope that these Typescript interview questions will be useful for you to be successful in the interview.

We are going to cover 10 frequently asked TypeScript interview questions and answers in 2021. Let’s have a look below:

TypeScript Interview Questions and Answers

Q1) Define TypeScript and explain what sets it apart from JavaScript?

Answer: TypeScript is regarded as the superscript of JavaScript. We use TypeScript to develop large applications. It comes with interfaces, classes, and optional static typing. It is regarded as a set of tools as well as a programming language. It assists developers in code refactoring. Also, developers can take advantage of tools which are highly productive. Now let’s take a look at the main differences between JavaScript and TypeScript below.

Programmers love to work in an object-oriented fashion and TypeScript has made this possible since it supports classes. In the case of JavaScript, it uses reusable components. TypeScript comes with interfaces whereas JavaScript does not. JavaScript doesn’t support static typing whereas TypeScript does support. JavaScript doesn’t provide optional parameters where Typescript does.

Q2) What are the data types supported by TypeScript? How would you implement inheritance with TypeScript?

Answer: Typescript supports data types which are usually supported by all other languages. Let’s have a look:

  • String: All character values.
  • Number: Any numerical value can be assigned here.
  • Array: It can be a list that constitutes numbers.
  • Boolean: Boolean can take only false or true as values.
  • Enum: You can come up with data type which is user-defined.

If you wish to implement inheritance in Typescript, then you may use the extends keyword:

class Scavenger {
  name: string;
  constructor(name: string) { = name; 
  run(meters: number = 0) {
    console.log(`${} ran ${meters}m.`);
class Dog extends Scavenger {
  constructor(name: string) { 
  run(meters = 6) {;
class Rat extends Scavenger {
  constructor(name: string) { 
  run(meters = 40) {;
let dodo = new Dog("Dodo the Dog");
let jerry: Scavenger = new Rat("Jerry the Rat");;;

Q3) What is tsconfig.json in TypeScript File?

Answer: We use this file to show that the directory is the root of the project. This file has information regarding compiler options and root files. Also, with the help of this file, you can streamline the building process. Let’s take a look at an example below to have some clarity:

    "compilerOptions": {
        "module": "commonjs",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true
    "files": [

Q4) Define Typescript Fat Arrow or Lambda Functions?

Answer: The arrow function is also referred to as lambda function. It behaves like an additional feature. You need to remember the fact that this function doesn’t come with a name.

var calculate = (x: number, y: number) => x * y;
console.log(calculate(5, 5))
// Output: 25

In the example as mentioned earlier, we => operator stands for arrow/lambda operator. Here x and y are parameters and (x * y) is regarded as the body of a function.

let addition = (x: number, y: number): number => { return x + y; }
console.log(addition(10, 19));
// Result = 29
let division = (x: number, y: number): number => { return x / y; }
console.log(division(20, 5));
// Result = 4
let multiplication = (x: number, y: number): number => { return x * y}
console.log(multiplication(36, 7));
// Result = 252

Q5) Explain Anonymous function?

Answer: Anonymous function doesn’t have named identified to refer.

let anonymousFuncton = function(x: number, y: number) {
  return x + y;
console.log(anonymousFuncton(20, 17)); 
//Result = is 37
console.log(anonymousFuncton(12, 'abc'));
// Result = It will return 12abc since since you passed the string in place of an integer.

Advance TypeScript Interview Questions 2021

Now let’s take a look at some of the advanced interview questions for TypeScript.

Q6) Explain how we can use a class outside a module where it was defined?

Answer: Usually, when we define a class, it has scope only inside the module. Therefore, you cannot access it beyond the module.

module School {
  class Student {
    constructor(name: string, email: string) { }
  let john = new Student('John', '');
let ann = School.Student('Ann', '');

As you can see, the variable ann will return error given the class Student cannot be accessed. If you wish to access the class, then you need to use the export keyword in TypeScript.

module School {
  export class Student {
    constructor(name: string, email: string) { }
  let john = new Student('John', '');
let ann = new School.Student('Ann', '');

At this point, the variable will not give error as we have accessed the Student class outside the module with the help of export keyword in TypeScript.

Q7) Define decorators in Typescript and give a couple of examples for decorators?

Answer: With the help of decorators, you will be able to modify a class as well as the members. With the help of decorators, you will be able to add Metaprogramming and annotations syntax. When they released decorators, it was meant to be an experiment. As for enabling decorators, you can only do that by editing the tsconfig.json file. Alternatively, you can enable with the help of a command line.

You need to use the following command line command for the same.

tsc –target ES5 –experimentalDecorators

Answer: To compile a Typescript file, you need to take the following steps:

  • 1) First and foremost, you need to make sure that Typescript engine has been enabled. You should go to the title bar and select options. You should also check for your username.
  • 2) Go to the project navigator. Select the TS files and right click on the files which are going to be compiled.
  • 3) Then you must select compile.
  • 4) You can have a reference to the compiled file in the HTML code.
  • 5) Once you are done with this, enter tsc in the command line to compile the file.

It’s time for us to find out the next Typescript interview questions:

Q9) Explain Typescript interfaces?

Answer: We use the interface to define the syntax of entities. It also defines events, methods, and properties. You only declare members here. We can define various members with the help of the interface. We declare interfaces with the help of the interface keyword.

interface Person { 
   mobile: number,
   dob: string,
   address: string,
   sayHello: ()=>string 

Q10) Optionally statically typed language, is the name used for Typescript. Why?

Answer: What it means is that compiler doesn’t have to bother about the variable type. You have the freedom to choose any data type to assign values to a variable. Typescript has no business in throwing an error there.

var valueType: any = 4;
valueType = 5; // 5
valueType = false; // Boolean.
valueType = 'This is an example of string';

As you can see in the example, you can declare any datatype.

Age calculator tool

🎂✨ Discover your age in detail and with countdown to your next birthday with fun facts! 🎈🎉

Calculate your age now!
Digamber - Author

Hi, I'm Digamber Singh, a New Delhi-based full-stack developer, tech author, and open-source contributor with 10+ years' experience in HTML, CSS, JavaScript, PHP, and WordPress.