Example
The following form passes the entered employee data to a factory function which creates a new Employee object, including derived properties like full name and email address.
interface EmployeeData {
firstName: string;
lastName: string;
jobTitle: string;
}
function createEmployee(
emp: EmployeeData,
domain: string,
): Employee {
const id = generateEmployeeId();
const fullName = generateFullName(emp);
const email = generateEmail(emp, domain);
return {
id,
...emp,
fullName,
email,
};
}
const employee = createEmployee(emp, "example.com");