- Related
- Java MCQ
- Java Interview Question
- Java Tutorial
- React MCQ
- React Interview Question
- Node MCQ
- Node Interview Question
- Angular MCQ
- Angular Interview Question
- HTML MCQ
- HTML Interview Question
- CSS MCQ
- CSS Interview Question
- JavaScript MCQ
- JavaScript Interview Question
- MYSQL MCQ
- MYSQL Interview Question
- DotNet MCQ
- DotNet Interview Question
- C Sharp MCQ
- C Sharp Interview Question
- Go Interview Question
- Flutter MCQ
- Flutter Interview Question
- Flutter Tutorial
- Spring Framework MCQ
- Spring Framework Interview Question
- Spring Boot Interview Question
TypeScript Interview Questions
1
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. 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.
2
What is the function of the .map file in TypeScript?The .map file in TypeScript is used for debugging code. The .map can be used by setting the sourcemap compiler option as true in the tsconfig.json.
3
What does the Record type in TypeScript do?The Record type in TypeScript helps you create a typed map, allowing you to perform various functions, including defining map tiles and translating coordinate systems to scale.
4
What are some disadvantages associated with TypeScript?Some disadvantages of using TypeScript include:
- TypeScript as a language does not support abstract classes
- TypeScript takes a long time to compile code
- Definition files are necessary while using 3rd party libraries in TypeScript
5
What is the function of the Omit type in TypeScript?This is one of the most common TypeScript interview questions asked at developer interviews. The Omit type is primarily used to exclude certain properties from a class.
6
How to pass options to TypeScript compiler?Through command line arguments or tsconfig.json file. If file tsconfig.json located in some directory, that means this root of TypeScript project. There are such options available: compilerOptions,files,typeRoots, include, exclude.
7
Difference between typescript and javascript?- Typescript is a superset of JavaScript whereas JavaScript is a scripting language.
- Typescript has an interface concept but JavaScript havan't.
- TypeScript doesn't run in the browser where JavaScript runs.
- TypeScript has classes whereas JavaScript has functions.
- Typescript support module whereas JavaScript doesn't support modules.
- In typescript Number, a string is the interfaces whereas In, JavaScript Number, string are the Object.
8
How do you install TypeScript?npm install -g typescript
9
Who developed Typescript and what is the current stable version available?Anders Hejlsberg developed TypeScript. The current stable version of TypeScript is 3.9.7.
10
What is union type?Variable should be declared with union type if it can be set with values of different types. It can be useful when you need to return correct result or null value, for example in find function.
11
What does the pipe(|) mean in typescript?This is called union type in typescript.
A union type describes a value that can be one of several types.
12
How do you declare an undefined variable?var name:string; var phone:int;
13
What are TypeScript collections?Like other programing languages Typescript also has support for Collection, like Map, Set etc.
14
How you can use TS with jQuery, Angularjs and Reactjs?Angularjs is already integrated with Typescript.So, if you are using Angularjs CLI you don’t need to do anything special. For React and jQuery use Typescript’s @types and it will install all the dependencies. @types/ React @types / jQuery.
15
List out all the components of TypeScript.Below are the components of TypeScript :-
- Language
- TSC-(TypeScript Compiler)
- TSLS- (TypeScript Language Service)
16
What is the TypeScript Definition Manager?TypeScript Definition Manager (TSD) is a package manager used to search and install TypeScript definition files directly from the community-driven DefinitelyTyped repository.
17
What is JSX in TypeScript?JSX is an embeddable XML-like syntax and it is meant to be transformed into a valid JavaScript. JSX became popular with the React framework. TypeScript supports embedding, type checking, and compiling JSX directly into JavaScript.
18
What is “as” syntax in TypeScript?The “as” is the additional syntax for Type assertion in TypeScript. The reason for introducing the as-syntax is that the original syntax conflicted with JSX.
19
What is Triple-Slash Directive?Triple-slash directives are single-line comments containing a single XML tag. The contents of the comment are used as compiler directives.
20
What are Variables in TypeScript?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.
21
What are modules in TypeScript?A module is a powerful way of creating a group of related variables, functions, classes, and interfaces, etc. It can be executed within its own scope, but not in the global scope. Basically, you cannot access the variables, functions, classes, and interfaces declared in a module outside the module directly.
22
What is tsconfig.json file?The tsconfig.json file is a file which is in JSON format. In the tsconfig.json file, you can specify different 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.
23
What are Classes in TypeScript?TypeScript introduced classes so that they can avail the benefits of object-oriented techniques like encapsulation and abstraction. The class in TypeScript is compiled to plain JavaScript functions by the TypeScript compiler to work across platforms and browsers.
24
What are types in TS?Types in Typescript define the data-type. It helps in avoiding the wrong value passing. There are 2 different types:
Built in — String, Number, boolean, Null, Undefined, any
User Defined — Array, object, classes, interfaces
25
What Are The Benefits Of Typescript?TypeScript has the following benefits:
- Intellisense
- Impose coding guidelines
- Offers type checking
- It helps in code structuring
- Compile time error checking
- Use class-based object-oriented programming
26
What is an anonymous function?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.
27
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.
28
What is getters/setters in TypeScript?TypeScript supports getters/setters as a way of intercepting accesses to a member of an object. This gives you a way of having finer-grained control over how a member is accessed on each object.
29
What is an implicit Module in Typescript?A module is used to create a set of related variables, functions, classes, and interfaces, etc in the Typescript. The internal and external module has two categories of Typescript.
30
What is the advantage of Arrow function in TypeScript?The two significant benefits that Arrow function in TypeScript offers:
- They are less verbose compared to traditional functions.
- This function takes the “this” from its surroundings.
31
What is static typing in TypeScript?In TypeScript, static typing means parameters, variables, and object members have types that compiler recognizes at the time of compile. This helps in detecting early errors faster than unit test runs. It also greatly helps IDEs with auto-completion and API exploration with statically typed DOM.
32
How to check null and undefined in typescript?By using a juggling check, we can check both null and undefined: if(x==null){}.
33
What is the difference between var and let in Typescript?- var declaration is done at function scoped and let declaration is done at block scoped.
- var will allow you to re-declare the same variable in the same scope, whereas let will not.
34
What does it mean by Semantic HTML?Semantic HTML is a type of coding style in which tags will have texts that need to display on the user interface. Bold, Italic tags should not be used to represent Semantic HTML.
35
What is super in TypeScript?Super is a TypeScript keyword which can be used by developers in expressions for base class constructor and base class properties reference. This call is only allowed in constructors of derived classes. Call for this keyword consist the keyword super with an argument list closed in parentheses.
36
What is the export class in TypeScript?In TypeScript, an extra line is added to the JS code using the export class which is then used to add an exported item within a module.
37
Which keyword is used for inheritance in TypeScript?TypeScript uses the keyword ‘extends’ to support inheritance. The syntax will be as following:
class child_class_name extends parent_class_name
38
What does the ‘Record’ type do?It allows you to create a typed map.
39
When to use the ‘unknown’ keyword?When you don’t want to use the "any" keyword or/and don’t know the exact type up front but want to assign it later on.
40
What is tuple in TypeScript?Tuple is collection of heterogeneous values or it store multiple different-different type data type values. Below is the example for the same.
var fileData = [“Alia”,90,”Shweta”,45];
41
Describe pop() and push() method in tuple.- push() – this used to append the value.
- pop()- this used to removed and return the last value.
42
What are TypeScript ambients, and when are they required?Ambient decorations inform the compiler about real source code located elsewhere. If the source changes, you must update the documentation; otherwise, you’ll run into compiler issues.
43
What is the extension of TypeScript?TypeScript Definition file (with .d.ts extension) provides definition for external JavaScript libraries.
44
What is “never” in TypeScript?The “never” type represents values that have never occurred. Additionally, variables constricted by type guards that can never be true also acquire the type never.
For example, never is a function expression’s return type.
45
Explain TypeScript decorators.Class, method, accessor, property, and parameter declarations can all be given a specific treatment by applying a decorator. The decorator annotates and includes metadata to the code.
46
Does TypeScript support object-oriented programming concepts?Yes, TypeScript supports object-oriented programming concepts like classes, interfaces, and inheritance.
47
What are TypeScript’s three “simple types”?Boolean, Number, and String are the three main 'simple types' in TypeScript.
48
What are numeric enums’ first value defaulted to?Numeric enum's first value is defaulted to 0.
49
What is a closure?Simply said, a closure is a function that can access its outside scope even when operating outside of it. Every time a function is declared inside of another function in JavaScript, a closure is produced because each function has its own scope due to the function-scoped nature of the language.
50
What is contextual typing in TypeScript?Contextual typing is an extremely useful feature of TypeScript, in which the language can automatically work out the type of a particular variable from the types of the variables that have produced it in an equation.