Recall & Review
beginner
What is a type alias in TypeScript?
A type alias is a way to give a new name to a type. It helps make code easier to read and reuse by creating a simple name for complex types.
Click to reveal answer
beginner
How do you create a type alias for a string in TypeScript?
You use the
type keyword followed by the new name and the type. For example: type Name = string;
Click to reveal answer
intermediate
Can type aliases represent union types? Give an example.
Yes, type aliases can represent union types. For example:
type Status = "success" | "error" | "loading";This means
Status can be one of those three string values.Click to reveal answer
intermediate
What is the difference between a type alias and an interface in TypeScript?
Type aliases can name any type, including primitives, unions, and tuples. Interfaces describe object shapes and can be extended. Type aliases cannot be reopened to add new properties, but interfaces can.
Click to reveal answer
beginner
Show how to create a type alias for an object with properties
id (number) and name (string).You write:
type User = { id: number; name: string; }; This creates a new type called User representing that object shape.Click to reveal answer
Which keyword is used to create a type alias in TypeScript?
✗ Incorrect
The
type keyword is used to create type aliases.What does this type alias represent?
type ID = number | string;
✗ Incorrect
The union
number | string means ID can be either a number or a string.Can a type alias be used to name a tuple type?
✗ Incorrect
Type aliases can name tuple types, for example:
type Point = [number, number];Which of these can type aliases NOT do?
✗ Incorrect
Type aliases cannot be reopened to add new properties or extend like interfaces can.
What is the correct syntax to create a type alias for an object with a string property 'title'?
✗ Incorrect
The correct syntax uses
type followed by the name and the object shape.Explain what a type alias is and how it helps in TypeScript programming.
Think about giving a nickname to a type.
You got /4 concepts.
Describe the difference between a type alias and an interface in TypeScript.
Focus on their capabilities and usage.
You got /4 concepts.