1. What are the main data types in TypeScript?
Built-in types include string, number, boolean,
null, undefined, any, and void. User-defined types are
arrays, enums, classes, and interfaces.
2. How does TypeScript handle arrays?
Arrays in TypeScript are static and only allow elements
of a specified type.
3. What are the three ways to declare variables in
TypeScript?
var for function-scoped variables, let for blockscoped variables, and const for constants.
4. What is the any type in TypeScript?
The any type allows a variable to store values of any
data type.
5. What are the advantages of TypeScript?
Strong typing, better error handling during
development, and support for modern JavaScript features.
6.What is the void type in TypeScript?
void is used to represent functions that do not return
a value.
7. What is the null type in TypeScript?
It represents the absence of a value and can be
explicitly assigned to variables.
8. Can TypeScript objects have optional properties?
Yes, optional properties can be declared using the ?
symbol.
9. What is the never type?
It represents values that never occur, often used in
functions that always throw errors or run indefinitely.
10. What are enums in TypeScript?
Enums allow you to define a set of named constants,
which can be either numeric or string-based.
11. Is TypeScript a strictly statically typed language?
No, it is optionally statically typed, meaning you can
choose when to use strict typing.
12. What is the typeof operator in TypeScript?
typeof is used to check the type of a variable.
13. What are interfaces in TypeScript?
Interfaces define a structure for objects, dictating what
properties or methods an object must have.
14. What is the difference between classes and interfaces?
Classes can implement behavior (methods), while
interfaces define a structure without implementation.
15. How do you compile TypeScript into JavaScript?
Use the tsc command to compile .ts files into .js
16. What are modules in TypeScript?
Modules allow grouping of classes, functions, and
interfaces into separate files and can be imported/exported.
17. What are decorators in TypeScript?
Decorators are functions that add metadata or modify
the behavior of classes, methods, or properties.
18. What is union typing in TypeScript?
Union types allow a variable to store values of multiple
specified types.
19. What is a type alias?
Type aliases allow you to define custom names for
combined or complex types.
20. What is the in operator in TypeScript?
It checks if a specific property exists in an object.
21. What is type inference?
Type inference automatically assigns a type to
variables based on their assigned values.
22. How does TypeScript support Object-Oriented
Programming (OOP)?
TypeScript supports OOP principles like encapsulation,
abstraction, inheritance, and polymorphism.
23. What is the readonly property in TypeScript?
readonly is used to create immutable object
properties.
24. What is the use of tsconfig.json?
It configures the TypeScript compiler and defines root
files and compiler options.
25. What are mixins in TypeScript?
Mixins allow the reuse of partial class behavior in other
classes through composition.
