Frequently asked questions and answers of TypeScript in Programming Technologies of Computer Science to enhance your skills, knowledge on the selected topic. We have compiled the best TypeScript Interview question and answer, trivia quiz, mcq questions, viva question, quizzes to prepare. Download TypeScript FAQs in PDF form online for academic course, jobs preparations and for certification exams .
Intervew Quizz is an online portal with frequently asked interview, viva and trivia questions and answers on various subjects, topics of kids, school, engineering students, medical aspirants, business management academics and software professionals.
Question-1. What is TypeScript?
Answer-1: TypeScript is a strongly typed superset of JavaScript developed by Microsoft, compiled to JavaScript.
Question-2. What are the key features of TypeScript?
Answer-2: Key features include static typing, interfaces, generics, classes, and ES6+ features.
Question-3. What is the difference between TypeScript and JavaScript?
Answer-3: TypeScript adds static types, interfaces, and compile-time checks to JavaScript.
Question-4. How do you install TypeScript?
Answer-4: Install using npm: npm install -g typescript.
Question-5. What is the file extension for TypeScript?
Answer-5: TypeScript files use the .ts extension.
Question-6. How do you compile a TypeScript file?
Answer-6: Use the tsc command: tsc filename.ts.
Question-7. What is the TypeScript compiler?
Answer-7: The TypeScript compiler, tsc, converts TypeScript code into JavaScript.
Question-8. What are TypeScript interfaces?
Answer-8: Interfaces define the structure of objects, enforcing property names and types.
Question-9. What is the any type in TypeScript?
Answer-9: The any type disables type checking, allowing a variable to hold any value.
Question-10. What is the unknown type in TypeScript?
Answer-10: The unknown type is a safer alternative to any, requiring a type check before usage.
Question-11. What is the difference between any and unknown?
Answer-11: any allows unchecked operations; unknown requires explicit type checks before usage.
Question-12. What is a union type in TypeScript?
Answer-12: Union types allow variables to hold values of multiple types. Syntax: `type A = string
Question-13. What are enums in TypeScript?
Answer-13: Enums define named constants. Example: enum Color { Red, Green, Blue }.
Question-14. What is type inference in TypeScript?
Answer-14: TypeScript automatically determines the type of a variable based on its value.
Question-15. What is the never type in TypeScript?
Answer-15: The never type represents values that never occur, used for functions that throw or never return.
Question-16. What is the void type in TypeScript?
Answer-16: The void type indicates a function does not return a value.
Question-17. What is the difference between interface and type?
Answer-17: Both can define object types, but type is more flexible and supports unions and intersections.
Question-18. What are TypeScript generics?
Answer-18: Generics allow functions, classes, and interfaces to operate with various types. Syntax:
Question-19. How do you declare a tuple in TypeScript?
Answer-19: Tuples are declared using arrays with fixed types: [string, number].
Question-20. What is readonly in TypeScript?
Answer-20: readonly prevents modification of properties or variables.
Question-21. How do you implement inheritance in TypeScript?
Answer-21: Use the extends keyword. Example: class Child extends Parent { }.
Question-22. What are TypeScript decorators?
Answer-22: Decorators are special functions applied to classes, methods, or properties to modify their behavior.
Question-23. What is type assertion in TypeScript?
Answer-23: Type assertion tells the compiler the type of a variable. Syntax: variable as Type.
Question-24. How do you handle null and undefined in TypeScript?
Answer-24: Use union types (`string
Question-25. What is the keyof operator in TypeScript?
Answer-25: keyof gets the keys of a type as a union of string literals.
Question-26. How do you create a module in TypeScript?
Answer-26: Use export and import keywords to define and consume modules.
Question-27. What is the difference between abstract class and interface?
Answer-27: An abstract class can have implementations; interfaces cannot but define structure contracts.
Question-28. What are mapped types in TypeScript?
Answer-28: Mapped types create new types by transforming properties of an existing type. Example: Partial
Question-29. What is the purpose of the Partial utility type?
Answer-29: Partial
Question-30. What is the purpose of the Readonly utility type?
Answer-30: Readonly
Question-31. What are utility types in TypeScript?
Answer-31: Utility types like Partial, Readonly, and Pick simplify type transformations.
Question-32. What is the Pick utility type?
Answer-32: Pick
Question-33. What is the Record utility type?
Answer-33: Record
Question-34. What is the Exclude utility type?
Answer-34: Exclude
Question-35. What is the Omit utility type in TypeScript?
Answer-35: Omit
Question-36. What is a namespace in TypeScript?
Answer-36: Namespaces group related code to avoid global scope pollution.
Question-37. What is the purpose of the extends keyword in TypeScript?
Answer-37: extends is used in generics and classes for inheritance or type constraints.
Question-38. What are inline types in TypeScript?
Answer-38: Inline types define types directly where they're used, without creating reusable type aliases or interfaces.
Question-39. What is the strict flag in TypeScript?
Answer-39: The strict flag enables all strict type-checking options.
Question-40. How does TypeScript support React?
Answer-40: TypeScript supports React using .tsx files, adding type safety to components and props.
Question-41. What is the difference between export and default export?
Answer-41: export can export multiple members; default export exports a single default member.
Question-42. What is the typeof operator in TypeScript?
Answer-42: typeof gets the type of a variable or object.
Question-43. What is the as keyword in TypeScript?
Answer-43: The as keyword is used for type assertions.
Question-44. What is the globalThis object in TypeScript?
Answer-44: globalThis provides a standard way to access the global object across environments.
Question-45. What is the purpose of TypeScript's config.json file?
Answer-45: The tsconfig.json file configures TypeScript compilation options.
Question-46. What is module augmentation in TypeScript?
Answer-46: Module augmentation adds new declarations to an existing module.
Question-47. What is the outDir option in tsconfig.json?
Answer-47: The outDir option specifies the output directory for compiled files.
Question-48. What is the difference between declare and export?
Answer-48: declare adds ambient declarations; export makes members accessible to other modules.
Question-49. What is the include option in tsconfig.json?
Answer-49: The include option specifies which files or directories to compile.
Question-50. How do you define optional properties in TypeScript?
Answer-50: Use ? after the property name. Example: propertyName?: string;.
Frequently Asked Question and Answer on TypeScript
TypeScript Interview Questions and Answers in PDF form Online
TypeScript Questions with Answers
TypeScript Trivia MCQ Quiz