TypeScript is a powerful, statically-typed superset of JavaScript that enhances development by adding type safety and modern features. It improves code quality, debugging, and scalability, making it ideal for large-scale applications. This guide covers TypeScript fundamentals, benefits over JavaScript, setup, and compilation.
Multiple Choice Questions (MCQs)
Section 1: What is TypeScript?
TypeScript is a superset of which programming language? a) Python b) Java c) JavaScript d) C#
Who developed TypeScript? a) Google b) Facebook c) Microsoft d) IBM
Which of the following is true about TypeScript? a) It is a backend language b) It is an extension of HTML c) It provides optional static typing d) It is only for front-end development
What file extension is used for TypeScript files? a) .ts b) .tsx c) .js d) .jsx
TypeScript was introduced in which year? a) 2010 b) 2012 c) 2014 d) 2016
Which feature of TypeScript helps in finding bugs during development? a) Dynamic typing b) Static typing c) Loose typing d) Strong typing
How does TypeScript handle JavaScript code? a) Converts JavaScript code to TypeScript b) Ignores JavaScript code c) Runs JavaScript code directly d) Transpiles JavaScript to TypeScript
Section 2: Benefits of TypeScript over JavaScript
What is one of the main benefits of using TypeScript over JavaScript? a) Faster execution time b) Less code required c) Enhanced code readability and maintainability d) Better browser compatibility
TypeScript helps in reducing bugs by providing which feature? a) Syntax highlighting b) Type inference c) Contextual typing d) Source maps
Which of the following is NOT a benefit of using TypeScript? a) Optional static typing b) Better tooling with editors c) Enhanced CSS integration d) Object-oriented programming features
How does TypeScript improve team collaboration? a) By enforcing coding standards b) By reducing file sizes c) By providing type annotations d) By allowing runtime checks
TypeScript code needs to be compiled into which format to run in browsers? a) Python b) Java c) JavaScript d) C++
How does TypeScript enhance the development process? a) By enabling machine learning features b) By adding static type-checking c) By integrating with SQL databases d) By improving network latency
TypeScript supports which of the following programming paradigms? a) Functional b) Object-oriented c) Procedural d) All of the above
What tool in TypeScript helps catch errors before runtime? a) Type checker b) Linter c) Debugger d) Profiler
Section 3: Setting up a TypeScript Development Environment
Which command is used to install TypeScript globally via npm? a) npm install -g typescript b) npm install typescript –save c) npm init typescript d) npm start typescript
What file is used to configure TypeScript settings? a) package.json b) tsconfig.json c) typescript.json d) config.json
Which editor is commonly used for TypeScript development due to its rich support and extensions? a) Notepad++ b) Eclipse c) Visual Studio Code d) Sublime Text
To compile TypeScript code into JavaScript, which command is used? a) ts-run b) ts-compile c) tsc d) tsbuild
How can you watch for changes in your TypeScript files and recompile automatically? a) tsc -auto b) tsc –watch c) tsc -monitor d) tsc –auto
The command tsc --init is used for what purpose? a) To start a new TypeScript project b) To install TypeScript dependencies c) To create a tsconfig.json file d) To upgrade TypeScript version
What is the purpose of the outDir option in tsconfig.json? a) Specify TypeScript version b) Define output directory for compiled JavaScript files c) Include additional libraries d) Enable debugging
Section 4: TypeScript Compiler (tsc) and Configuration
What does the strict option in tsconfig.json do? a) Enables strict mode for JavaScript b) Ensures all files are compiled c) Applies strict type-checking rules d) Makes TypeScript compilation faster
How can you exclude files from being compiled by TypeScript? a) Using the ignore option b) Using the exclude option c) Using the remove option d) Using the hide option
Which of the following compiles only one specified TypeScript file? a) tsc –all b) tsc [filename].ts c) tsc –file [filename] d) tsc -single [filename]
How can you enable ES6 features in TypeScript? a) Set “target” to “ES5” b) Set “target” to “ES6” c) Set “lib” to “ES6” d) Use “es6” command
What does the noImplicitAny option enforce? a) Disallows the use of any variable b) Disallows variables with type any c) Enables automatic type inference d) Forces strict null checks
How do you specify multiple files for TypeScript to compile in tsconfig.json? a) Using the include array b) Using the files array c) Using the compile array d) Using the input array
Which flag helps in debugging TypeScript code by generating source maps? a) –debug b) –sourceMaps c) –map d) –trace
If you want to compile TypeScript files into a specific version of ECMAScript, which option would you use? a) –ecma-version b) –compile-version c) –target d) –version
Answers
Qno
Answer
1
c) JavaScript
2
c) Microsoft
3
c) It provides optional static typing
4
a) .ts
5
b) 2012
6
b) Static typing
7
c) Runs JavaScript code directly
8
c) Enhanced code readability and maintainability
9
b) Type inference
10
c) Enhanced CSS integration
11
c) By providing type annotations
12
c) JavaScript
13
b) By adding static type-checking
14
d) All of the above
15
a) Type checker
16
a) npm install -g typescript
17
b) tsconfig.json
18
c) Visual Studio Code
19
c) tsc
20
b) tsc –watch
21
c) To create a tsconfig.json file
22
b) Define output directory for compiled JavaScript files