최신 typescript 및 reactjs 버전을 함께 사용하며 확장 클래스 및 해당 인터페이스의 확장에 문제가 있습니다.확장 클래스의 인터페이스를 확장하는 방법
/// <reference path="../typings/tsd.d.ts" />
import React = require('react');
interface P {
id: string
onChange: Function
error: string
}
interface S {
value: string
isValid: boolean
}
class BaseComponent extends React.Component<P, S> {
protected isValid(value) {
//do stuff
}
}
export default BaseComponent;
그리고 BaseComponent에서 확장 구성 요소 : 이제
/// <reference path="../typings/tsd.d.ts" />
import React = require('react');
import BaseComponent from './baseComponent';
interface P {
id: string
onChange: Function
error: string
required?: boolean
}
interface S {
value: string
isValid: boolean
somethingNew: string
}
class NameFieldContainer extends BaseComponent {
constructor(props: any) {
super(props);
this.state = {
value: '',
isValid: false,
somethingNew: 'Foo'
};
this.aMethod();
}
protected aMethod() {
this.setState({somethingNew: 'Bar'});
}
public render() {
const somethingNew = this.state.somethingNew;
return (
<div>{somethingNew}</div>
);
}
export default NameFieldContainer;
여러 폼 요소에 대한
내가 같이 보이는 BaseComponent을 만들었습니다 (모두 같은 검증 방법이) 내 컴파일러 (및 IDE)는 새로운 state.somethingNew 및 props.required 속성에 몇 가지 문제를 보여줍니다. 나는 이것을 확장하는 방법을 모른다. BaseComponent에 NameFieldContainer의 인터페이스를 사용해야한다는 것을 어떻게 가르 칠 수 있습니까?
고맙습니다! – Khazl