In this quiz we will cover Type Aliases in TypeScript
Question 1
What is a Type Alias in TypeScript?
A function that defines a new type
A way to create a new name for an existing type
A reserved keyword for defining interfaces
A feature used only for primitive types
Question 2
How do type aliases enhance code readability in TypeScript?
By providing an alias for complex data structures
By making primitive types more readable
By replacing all interfaces with type aliases
By reducing the number of functions in the code
Question 3
Which of the following is a valid use case for Type Aliases?
Defining a complex object structure
Creating a union of multiple types
Assigning a name to a function signature
All of the above
Question 4
What is the main difference between Type Aliases and Interfaces in TypeScript?
Type aliases can define primitive types, whereas interfaces cannot
Interfaces support method merging, whereas type aliases do not
Type aliases are always preferred over interfaces
Interfaces can define union types, whereas type aliases cannot
Question 5
Which of the following is a correct example of a type alias for a union type?
A variable with a single type
A type that can hold only one value
A type that combines multiple possible types
A type that restricts values to numbers only
Question 6
Can type aliases be used to define function signatures?
Yes, type aliases can be used to define function signatures
No, only interfaces can define function signatures
Only when using classes
Only with arrow functions
Question 7
What will happen if you try to extend a type alias using extends like an interface?
It will work as expected
It will throw a TypeScript error
It will merge with the existing type
It will be ignored by the TypeScript compiler
Question 8
How can you combine multiple type aliases in TypeScript?
Using the | (pipe) operator for union types
Using the & (ampersand) operator for intersection types
Both a and b
Type aliases cannot be combined
Question 9
What will be the output of the following code?
type ID = string | number;
let userID: ID = 42;
42
"42"
undefined
Compilation erro
Question 10
Why would you use a Type Alias instead of an Interface?
To define primitive types
To define complex object structures with unions
To define function signatures
All of the above
There are 10 questions to complete.