How To Deal With Component Extends Component Problem?
yuzhounanhai opened this issue · 1 comments
Hi, I have some questions about Component Extends Component. I know it's not recommended but it's a useful method in some cases. Currently, I'm a little confused about the following examples, could you please give me some advice?
// define
export interface ExampleProps {
propsA: string;
}
class Example extends React.Component<ExampleProps, {}> {
// ...
}
export default Example;
// use
<Example />In this case, I got an error tip from typescript:
Property 'propsA' is missing in type { propsA: string; }
And I use Generic Function to resolve Component Extends Component.
// define BaseClass
export interface BaseClassProps {
a: string;
}
class BaseClass<T extends BaseClassProps, S = {}> extends React.Component<T, S> {
// this component will use this.props.a
}
export default BaseClass;
// define SubClass
export interface SubClassProps extends BaseClassProps {
b: string;
}
class SubClass extends BaseClass<SubClassProps> {
// this component will use this.props.a and this.props.b
}
export default SubClass;
// use
<SubClass />Typescript check will be passed without telling me the property 'a' and 'b' being missed, while the type check is still working. (In the SubClass component, typescript will check both 'a' and 'b' type.)
So I want to ask what can I do to fix this issue, or do you have any other methods to deal with this case.
OK, I found it was caused by the webpack loader, I changed a loader, and it's not wrong to report now.