You are on page 1of 5

Frequently Asked Typescript Interview Questions and Answers

1. List some benefits of using Typescript?

• 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.

2. Tell the minimum requirements for installing Typescript. OR how can we get
TypeScript and install it?

• TypeScript can be installed and managed with the help of node via npm. To install
TypeScript, first ensure that the npm is installed correctly, then run the following
command which installs TypeScript globally on the system.

3. What are the variables in Typescript?

• The variable name must be an alphabet or numeric digits.


• The variable name cannot start with digits.
• The variable name cannot contain spaces and special character, except the
underscore(_) and the dollar($) sign

4. What is Typescript?

• 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.

5.Who developed Typescript and what is the current stable version of Typescript?

• The typescript was developed by Anders Hejlsberg, who is also one of the core
members of the development team of C# language.
• It is developed and maintained by Microsoft under the Apache 2 license. It was
designed for the development of a large application.

6. List some features of Typescript?

• Object Oriented Language


• Support JavaScript Libraries
• DOM Manipulation
• Typescript is Just Java

7. What are the disadvantages of TypeScript?

• 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.
8. How to compile a Typescript file?

• Here is the command which is followed while compiling a Typescript file into
JavaScript.
• $ tsc <TypeScript File Name>
• The result would be helloworld.js.

9. Does TypeScript supports function overloading as JavaScript doesn't support


function overloading?

• Yes, TypeScript support function overloading. But the implementation is odd. When
we perform function overloading in TypeScript, then we can implement only one
functions with multiple signatures.

10. How to generate TypeScript definition file from any .ts file?

• We can generate TypeScript definition file from any .ts file by using tsc compiler.
• It will be generating a TypeScript definition which makes our TypeScript file
reusable.

11. What is TypeScript Declare Keyword?

• We know that all JavaScript libraries/frameworks don't have TypeScript declaration


files, but we want to use them in our TypeScript file without any compilation errors.

12. Explain generics in TypeScript?

• TypeScript Generics is a tool which provides a way to create reusable components.


• It is able to create components that can work with a variety of data types rather than a
single data type. Generics provides type safety without compromising the
performance, or productivity.

13. What is tsconfig.json file?

• The tsconfig.json file is a file which is in JSON format.


• In the tsconfig.json file, we can specify various options to tell the compiler how to
compile the current project.
• The presence of a tsconfig.json file in a directory indicates that the directory is the
root of a TypeScript project.

14. Does TypeScript support all object-oriented principles?

• Encapsulation,
• Inheritance,
• Abstraction, and
• Polymorphism.

15. Why do we need TypeScript?

• TypeScript supports all JavaScript libraries because it is the superset of JavaScript.


• TypeScript support reusability by using the inheritance.
• TypeScript make app development quick and easy as possible, and the tooling support
of TypeScript gives us autocompletion, type checking, and source documentation.

16. What is TypeScript Definition Manager and why do we need it?

• TypeScript Definition Manager (TSD) is a package manager used to search and install
TypeScript definition files directly from the community-driven Definitely Typed
repository.

17. How does TypeScript support optional parameters in function as in JavaScript


every parameter is optional for a function?

• Unlike JavaScript, the TypeScript compiler will throw an error if we try to invoke a
function without providing the exact number and types of parameters as declared in
its function signature.
• To overcome this problem, we can use optional parameters by using question mark
sign ('?')

18. What are Mixins?

• In Javascript, Mixins are a way of building up classes from reusable components is to


build them by combining simpler partial classes called mixins.

19. Which object oriented terms are supported by TypeScript?

• Modules
• Classes
• Interfaces
• Inheritance
• Data Types
• Member functions

20. What is default visibility for properties/methods in TypeScript classes?

• Public is the default visibility for properties/methods in TypeScript classes.

21. Explain Decorators in Typescript?

• A Decorator is a special kind of declaration that can be applied to classes, methods,


accessor, property, or parameter.
• Decorators are simply functions that are prefixed @expression symbol, where
expression must evaluate to a function that will be called at runtime with information
about the decorated declaration.

22. Is Native Javascript supports modules?

• No. Currently, modules are not supported by Native JavaScript.


• To create and work with modules in Javascript we require an external like
CommonJS.
23. What is namespace in Typescript?

• A namespace is a way that is used for logical grouping of functionalities. Namespaces


are used to maintain the legacy code of typescript internally.

24. What is the difference between the internal module and the external module?

Internal Module External Module


An external module is written as a separate
Internal modules are declared using Module
source file that contains at least one import or
Declarations that specify their name and body.
export declaration.
External modules are separately loaded bodies
Internal modules are local or exported
of code referenced using external module
members of other modules
names.

25. How to Call Base Class Constructor from Child Class in TypeScript?

• super() function is used to called parent or base class constructor from Child Class.

26. How is TypeScript different from JavaScript?

JavaScript TypeScript
It was developed by Netscape in 1995 It was developed by Anders Hejlsberg in 2012
It supports object-oriented programming
It is just a scripting language. concept like classes, interfaces, inheritance,
generics, etc.
JavaScript doesn't support generics. TypeScript supports generics.

27. What are the Modules in Typescript?

• 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.

28. How do you implement inheritance in TypeScript?

• Inheritance is a mechanism that acquires the properties and behaviors of a class from
another class.
• It is an important aspect of OOPs languages and has the ability which creates new
classes from an existing class.
• The class whose members are inherited is called the base class, and the class that
inherits those members is called the derived class.

29. What do you understand by classes in Typescript? List some features of classes.
• 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.

30. What do you mean by interfaces? Explain them with reference to Typescript.

• An Interface is a structure which acts as a contract in our application.


• It defines the syntax for classes to follow, it means a class that implements an
interface is bound to implement all its members.
• It cannot be instantiated but can be referenced by the class object that implements it.

You might also like