• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
Switch to Dark Mode

Type Aliases in TypeScript

In this quiz we will cover Type Aliases in TypeScript

Last Updated : Feb 11, 2025
Discuss
Comments

Question 1

What is a Type Alias in TypeScript?

  • A

    A function that defines a new type

  • B

    A way to create a new name for an existing type

  • C

    A reserved keyword for defining interfaces

  • D

    A feature used only for primitive types

Question 2

How do type aliases enhance code readability in TypeScript?

  • A

    By providing an alias for complex data structures

  • B

    By making primitive types more readable

  • C

    By replacing all interfaces with type aliases

  • D

    By reducing the number of functions in the code

Question 3

Which of the following is a valid use case for Type Aliases?

  • A

    Defining a complex object structure

  • B

    Creating a union of multiple types

  • C

    Assigning a name to a function signature

  • D

    All of the above

Question 4

What is the main difference between Type Aliases and Interfaces in TypeScript?

  • A

    Type aliases can define primitive types, whereas interfaces cannot

  • B

    Interfaces support method merging, whereas type aliases do not

  • C

    Type aliases are always preferred over interfaces

  • D

    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

    A variable with a single type

  • B

    A type that can hold only one value

  • C

    A type that combines multiple possible types

  • D

    A type that restricts values to numbers only

Question 6

Can type aliases be used to define function signatures?

  • A

    Yes, type aliases can be used to define function signatures

  • B

    No, only interfaces can define function signatures

  • C

    Only when using classes

  • D

    Only with arrow functions

Question 7

What will happen if you try to extend a type alias using extends like an interface?

  • A

    It will work as expected

  • B

    It will throw a TypeScript error

  • C

    It will merge with the existing type

  • D

    It will be ignored by the TypeScript compiler

Question 8

How can you combine multiple type aliases in TypeScript?

  • A

    Using the | (pipe) operator for union types

  • B

    Using the & (ampersand) operator for intersection types

  • C

    Both a and b

  • D

    Type aliases cannot be combined

Question 9

What will be the output of the following code?

TypeScript
type ID = string | number;
let userID: ID = 42;


  • A

    42

  • B

    "42"

  • C

    undefined

  • D

    Compilation erro

Question 10

Why would you use a Type Alias instead of an Interface?

  • A

    To define primitive types

  • B

    To define complex object structures with unions

  • C

    To define function signatures

  • D

    All of the above

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