简体   繁体   中英

How to exclude interface property from extended class in typescript

I have two classes

interface IBasicFunctionalityProps {
  propertySpecificForBasicFunctionality: MyType;
  propertyNotSpecificForBasicFunctionality: boolean;
}

class BasicFunctionalityClass extends React.Component<IBasicFunctionalityProps> {...}

class ExtendedFunctionalityClass extends BasicFunctionalityClass

BasicFunctionality has two props and it's ok. But in inherited class ExtendedFunctionalityClass i don't want to have propertySpecificForBasicFunctionality property. How i can omit this property?

It's totally against concept of inheritance.

In my opinion you should split IBasicFunctionalityProps interface into two separate interfaces and implement them as needed. This way you could achieve desired behaviour.

Anyway, React dissuades using inheritance. https://reactjs.org/docs/composition-vs-inheritance.html#so-what-about-inheritance

Best regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM