If we were to have these types:
interface Person {
name: string;
}
interface Agent extends Person {
code: number;
}
and have this code:
const agent: Agent = {
name: 'name',
code: 123
}
How would you cast the type Agent
into Person
and remove the code field? When I try to do this:
const person: Person = agent as Person
console.log(person) // Still contains the fields of agent
This is a simple example, but in my real usecase the object has a lot more fields. I've also tried:
person: Person = {
...agent
}
Another post I looked at that didn't work for my case: Restrict type by super class in interface.