无法将流类型设置为反应状态
Cannot set flow types to react state
我根据这个答案创建了一个反应组件并设置了流程类型:。但是还是报错:object literal this type is incompatible with object type
我的代码:
class Login extends Component {
constructor(props) {
super(props);
this.state = {
email: ''
};
}
state: {
email: String;
};
}
知道发生了什么吗?
您必须使用 string
而不是 String
。 They are not the same.
Remember that string and String are different types.
A string is a literal value like "foo" or the result of an expression
like "" + 42.
A String is a wrapper object created by the global
String(x) constructor.
这个
state: {
email: String;
};
应该是
state: {
email: string;
};
因此您的组件应该如下所示
class Login extends Component {
state: {
email: string;
};
constructor(props) {
super(props);
this.state = {
email: ''
};
}
}
我根据这个答案创建了一个反应组件并设置了流程类型:object literal this type is incompatible with object type
我的代码:
class Login extends Component {
constructor(props) {
super(props);
this.state = {
email: ''
};
}
state: {
email: String;
};
}
知道发生了什么吗?
您必须使用 string
而不是 String
。 They are not the same.
Remember that string and String are different types.
A string is a literal value like "foo" or the result of an expression like "" + 42.
A String is a wrapper object created by the global String(x) constructor.
这个
state: {
email: String;
};
应该是
state: {
email: string;
};
因此您的组件应该如下所示
class Login extends Component {
state: {
email: string;
};
constructor(props) {
super(props);
this.state = {
email: ''
};
}
}