Type Alias Person Formatter
Write a TypeScript function that uses a type alias. Define a type alias Person = { name: string; age: number }. Write a function that takes a Person and returns a formatted string.
Type aliases allow you to define reusable type definitions. They can represent object shapes, union types, or any other type. Unlike interfaces, type aliases can represent primitive types, unions, and tuples.
Type aliases are defined with the type keyword and are a fundamental TypeScript feature for organizing types. They improve code readability by giving meaningful names to complex types.
Type aliases improve code maintainability by centralizing type definitions. When the type changes, only the alias needs updating rather than every function signature. They are particularly useful in large codebases where the same object shape appears in many function signatures.Type aliases improve code maintainability by centralizing type definitions. When the type changes, only the alias needs updating rather than every function signature. They are particularly useful in large codebases where the same object shape appears in many function signatures.
The type keyword in TypeScript can define object shapes, union types, intersection types, tuple types, and more. Unlike interfaces, type aliases cannot be extended but can represent any type including unions like string | number and primitives like string.
Type aliases are evaluated lazily and can reference themselves, enabling recursive type definitions for data structures like JSON trees or linked lists.
Example Input & Output
Algorithm Flow

Solution Approach
Write a TypeScript function that uses a type alias. Define a type alias Person = { name: string; age: number }. Write a function that takes a Person and returns a formatted string.
Type aliases allow you to define reusable type definitions. They can represent object shapes, union types, or any other type. Unlike interfaces, type aliases can represent primitive types, unions, and tuples.
Type aliases are defined with the type keyword and are a fundamental TypeScript feature for organizing types. They improve code readability by giving meaningful names to complex types.
Best Answers
function formatPerson(p: {name: string; age: number}): string {
return p.name + ' is ' + p.age + ' years old';
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
