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
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
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
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
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
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 with arrow functions
What will happen if you try to extend a type alias using extends like an interface?
It will throw a TypeScript error
It will merge with the existing type
It will be ignored by the TypeScript compiler
How can you combine multiple type aliases in TypeScript?
Using the | (pipe) operator for union types
Using the & (ampersand) operator for intersection types
Type aliases cannot be combined
What will be the output of the following code?
TypeScript
type ID = string | number ;
let userID : ID = 42 ;
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
Ready to go from coding beginner to development pro? Our DSA to Development Coding Guide has everything you need to crush coding interviews and ace real-world projects! Limited spots available!Enroll Now and Transform Your Coding Skills! Also get 90% fee refund on completing 90% of the course in 90 days ! Take the Three 90 Challenge today.
There are 10 questions to complete.
Take a part in the ongoing discussion View All Discussion