Recall & Review
beginner
What is a type alias for functions in TypeScript?
A type alias for functions lets you give a name to a function type, making it easier to reuse and understand the function's input and output types.
Click to reveal answer
beginner
How do you define a type alias for a function that takes two numbers and returns a number?
You write:
type Operation = (a: number, b: number) => number; This means Operation is a function type taking two numbers and returning a number.Click to reveal answer
beginner
Why use a type alias for functions instead of writing the function type inline?
Using a type alias makes your code cleaner and easier to read. It also helps when you use the same function type in many places, so you only write it once.
Click to reveal answer
intermediate
Can a type alias for a function include optional parameters?
Yes! You can mark parameters as optional with a question mark. For example:
type Greet = (name?: string) => void; means the function can be called with or without a name.Click to reveal answer
intermediate
Show an example of a type alias for a function that returns a Promise of a string.
Example:
type AsyncString = () => Promise<string>; This means the function returns a Promise that will give a string later.Click to reveal answer
How do you define a type alias for a function that takes a string and returns a boolean?
✗ Incorrect
Option B correctly defines a function type alias with parameter name and type, and return type.
What does this type alias mean?
type Fn = () => void;✗ Incorrect
The empty parentheses mean no arguments, and 'void' means no return value.
Can a type alias for a function include multiple parameters?
✗ Incorrect
You list parameters separated by commas inside parentheses with their types.
What is the benefit of using a type alias for functions?
✗ Incorrect
Type aliases improve readability and reuse but do not affect runtime behavior.
How do you mark a parameter as optional in a function type alias?
✗ Incorrect
A question mark after the parameter name marks it as optional.
Explain how to create and use a type alias for a function that adds two numbers.
Think about naming the function type and how to call a function with that type.
You got /4 concepts.
Describe the advantages of using type aliases for functions in TypeScript projects.
Consider how type aliases help when many functions share the same shape.
You got /4 concepts.