[英]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. BasicFunctionality
有两个道具,没关系。 But in inherited class ExtendedFunctionalityClass
i don't want to have propertySpecificForBasicFunctionality
property. 但是在继承的类ExtendedFunctionalityClass
我不想具有propertySpecificForBasicFunctionality
属性。 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. 我认为您应该将IBasicFunctionalityProps
接口拆分为两个单独的接口,并根据需要实现它们。 This way you could achieve desired behaviour. 这样,您就可以实现所需的行为。
Anyway, React dissuades using inheritance. 无论如何,React使用继承劝阻。 https://reactjs.org/docs/composition-vs-inheritance.html#so-what-about-inheritance https://reactjs.org/docs/composition-vs-inheritance.html#so-what-about-inheritance
Best regards 最好的祝福
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.