Is it possible to override an interface with a string in TypeScript?
Consider this example:
type RankList = "Manager" | "Staff"
interface EmployeeList {
id: string,
name: string,
department: string,
rank: "Staff",
manager: string
}
interface EmployeeList {
id: string,
name: string,
department: string,
rank: "Manager"
}
In this scenario, if the employee is listed as a "Manager," they do not have a "manager" field. However, if their rank is "Staff," then the field will have a mandatory "manager" field indicating who their manager is.
So far, I have used an optional field like this:
interface EmployeeList {
id: string,
name: string,
department: string,
rank: RankList,
manager?: string
}
But I would like to make it more stringent. Is there a way to achieve this?