TypeScript Questions
1. TypeScript is best described as:
A. A new programming language
B. A superset of JavaScript
C. A replacement for JavaScript
D. A database query language
B. A superset of JavaScript
2. What is the purpose of type annotations in TypeScript?
A. To make code run faster
B. To catch errors during compilation
C. To reduce file size
D. To enable multithreading
B. To catch errors during compilation
3. Interfaces in TypeScript are used for:
A. Creating new objects
B. Defining the shape of an object
C. Replacing classes
D. Handling exceptions
B. Defining the shape of an object
4. What does TypeScript's type inference do?
A. Always requires explicit types
B. Automatically determines types when possible
C. Converts JavaScript to TypeScript
D. Slows down compilation
B. Automatically determines types when possible
5. Generics in TypeScript allow:
A. Creating type-safe collections
B. Converting types to strings
C. Making all types nullable
D. Disabling type checking
A. Creating type-safe collections
6. What is the difference between type and interface?
A. type
can create unions, interface
cannot
B. interface
can be extended, type
cannot
C. Both are identical
D. type
is only for primitive types
A. type
can create unions, interface
cannot
7. Decorators in TypeScript are:
A. Functions that modify classes/methods
B. Special types of variables
C. Error handling mechanisms
D. Async/await syntax sugar
A. Functions that modify classes/methods
8. What does a type guard do?
A. Converts types automatically
B. Narrows down types within conditional blocks
C. Protects against runtime errors
D. Replaces interfaces
B. Narrows down types within conditional blocks
9. TypeScript supports which module systems?
A. Only CommonJS
B. Only ES Modules
C. Both CommonJS and ES Modules
D. No module system
C. Both CommonJS and ES Modules
10. What does strictNullChecks do?
A. Allows all variables to be null
B. Prevents null/undefined assignment errors
C. Disables type checking
D. Makes all types nullable by default
B. Prevents null/undefined assignment errors
11. What does Partial do?
A. Makes all properties optional
B. Makes all properties required
C. Converts to primitive types
D. Creates a new interface
A. Makes all properties optional
12. .d.ts files contain:
A. Runtime JavaScript code
B. Type declarations
C. HTML templates
D. CSS styles
B. Type declarations
13. How are tuples different from arrays?
A. Tuples have fixed-length and specific types
B. Arrays can’t contain numbers
C. Tuples are JavaScript-only
D. Arrays must be homogeneous
A. Tuples have fixed-length and specific types
14. The never type represents:
A. A value that never occurs
B. A nullable value
C. An unknown type
D. Any possible value
A. A value that never occurs
15. Namespaces are primarily used for:
A. Logical grouping of code
B. Replacing modules
C. Creating new types
D. Async operations
A. Logical grouping of code
16. Mixins allow:
A. Multiple inheritance in TypeScript
B. Converting classes to interfaces
C. Disabling type checking
D. Creating circular dependencies
A. Multiple inheritance in TypeScript
17. The key advantage of TypeScript is:
A. No need for testing
B. Static type checking
C. Better runtime performance
D. Smaller bundle size
B. Static type checking