TypesScript interview
TypesScript interview
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.
5. Mention some of the features of TypeScript
Cross-Platform: The TypeScript compiler can be installed on any Operating System
such as Windows, MacOS, and Linux.
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.
6. What are the Benefits of using TypeScript?
TypeScript is fast, simple, easy to learn and runs on any browser or JavaScript
engine
It is similar to JavaScript and uses the same syntax and semantics.
TypeScript is an Object-
JavaScript is a Scripting language
Oriented language
It has a feature known as Static typing It does not have static typing
TypeScript gives support for modules JavaScript does not support modules
It does not support optional parameter
It supports optional parameter function
function
8. What are Differences between Interfaces and types?
Interfaces extend syntax is different to types
Interfaces can be merged - types cannot: Along the same lines, types cannot be
merged, while interfaces can if you declare them multiple times.
Interfaces cannot extend a primitive: While we can create a type which can be an
alias for a primitive type like string, interface cannot do this.
9. What are Interfaces in TypeScript?
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.
10. What are the access modifiers supported by TypeScript?
TypeScript supports access modifiers public, private and protected which determine the
accessibility of a class member:
Public – All the members of the class, its child classes, and the instance of the
class can access.
Protected – All the members of the class and its child classes can access them.
But the instance of the class can not access.
Private – Only the members of the class can access them.
If an access modifier is not specified it is implicitly public as that matches the convenient
nature of JavaScript.