一、单层继承
1)基础组件
export interface BaseProps { name: string; } export interface BaseState { age: number; } export class BaseComp<P extends BaseProps = any, S extends BaseState = any> extends React.Component<P, S> { state = { name: '123', } as S; }
2)上层组件
interface BetterProps extends BaseProps { gender: 'man' | 'female'; } interface BetterState extends BaseState { language: string; } class BetterComp extends BaseComp<BetterProps, BetterState> { state = { ...this.state, language: '中文', } }
二、组合继承
1)基础组件