Programming Language: Typescript
I am looking to combine the properties of two interfaces as the value of an indexable-type within a third interface.
Interface 1:
export interface Employee {
id: string
name: string
}
Interface 2:
export interface Department {
department: string
}
My goal is to define an interface that mirrors this structure:
export interface EmployeeDetails {
employees: {
[key: string]: {
employeeDetails: EmployeeWithDepartment
}
}
}
In this case, EmployeeWithDepartment
includes:
export interface EmployeeWithDepartment extends Employee {
departmentDetails: Department
}
Is there a method to construct the EmployeeDetails
interface without explicitly defining EmployeeWithDepartment
? Is there a way to link both Employee and Department directly in the EmployeeDetails interface?
PS: I am fairly new to JS & TypeScript, so any advice or alternative approaches are welcome!