一、基础组件
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; }
二、上层组件
interface BetterProps extends BaseProps { gender: 'man' | 'female'; } interface BetterState extends BaseState { language: string; } class BetterComp extends BaseComp<BetterProps, BetterState> { state = { ...this.state, language: '中文', } }