Intersection Types (&)
With intersection types different types can be blended into one unit, these kind of type will hold all properties belonging to intersected types.
Example: In the given below example we are combining Person and Employee Types.
interface Person {
name: string;
age: number;
}
interface Employee {
employeeId: number;
department: string;
}
type EmployeePerson = Person & Employee;
const pankaj: EmployeePerson = {
name: "Pankaj Bind",
age: 20,
employeeId: 12345,
department: "Engineering"
};
console.log(pankaj);
Output:
{
name: 'Pankaj Bind',
age: 20,
employeeId: 12345,
department: 'Engineering'
}
Type Manipulation in TypeScript
TypeScript offers strong tools for types manipulation and transformation, these tools allow programmers to create new types by composing, intersecting, unionizing, mapping and conditioning existing ones, in this article we will investigate some of the advanced type-manipulation features in TypeScript including:
Table of Content
- Intersection Types (&)
- Union Types (|)
- Mapped Types
- Conditional Types
Contact Us