In my software development project, I am working with an Interface
and I want to create computed properties that rely on other properties within the interface.
For instance, the Person
interface includes properties for first name and last name. How can I enhance the Person
interface so that it includes a new property called fullName
, which combines the values of the first name and last name properties for all implementors?
interface Person {
firstName: string;
lastName: string;
}
class Pilot implements Person {
constructor(public firstName: string, public lastName: string) {}
}
class Sailer implements Person {
constructor(public firstName: string, public lastName: string) {}
}
const pilot = new Pilot("Joe", "Alpha")
const sailer = new Sailer("Jane", "Beta")
// How can I extend `Person` interface to include fullName property?
console.log(pilot.fullName) // Joe Alpha
console.log(sailer.fullName) // Jane Beta