Type that omits all inherited properties?

Say we have
class Person {
age: number
}
class Child extends Person {
play() {
//...
}
}
class Person {
age: number
}
class Child extends Person {
play() {
//...
}
}
I want a type that incudes only the fields from Child without the inherited properties. For example, type OnlyChild = { play: () => void }. Is that possible. I know I can use Omit<> but I don't know what the properties of Person are.
3 Replies
benten
bentenOP3y ago
wait type OnlyNonInherited = Omit<B, keyof A>; maybe? Except I don't know A
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Froxx
Froxx3y ago
If you think about types like types instead of interfaces they will extend each other by doing type B = A & {bProp: any}, so in that syntax compared to the actual extend one used in interfaces, you can see it's pretty much just a concatenation of multiple types, not a layering. Therefore I think this might not be possible. May I ask you for the purpose of that? There might be a different approach doing what you're aiming for
Want results from more Discord servers?
Add your server