0
我试图在对象添加属性是这样的:流不能指派属性:计算财产转让/元素
request(options:HttpRequestData): Promise<any> {
options.headers = options.headers || {};
options.headers['Accept'] = 'application/json';
options.headers['Content-Type'] = 'application/json'; // Error
return this._request(options);
}
但它的主要错误:
options.headers['Content-Type'] = 'application/json';
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
assignment of computed property/element. Computed property/element cannot be assigned on possibly undefined value
HttpRequestData是一个对象类型:
type HttpRequestData = {
url:string,
method:string,
headers?:Object,
body?:string,
};
Assiging只是一个值到options.header(在这种情况下,“接受”)的作品,但是当我尝试失败两个或更多。
Flow中的单个赋值和多个赋值以及如何将这些属性赋值给options.headers对象有什么区别?
任何建议将非常感激。
看来,没有类型的对象,在流。我的意思是它的对象类型的语法不正确。 –
@TarasYaremkiv谢谢,所以我只是更新了header的属性:headers?:{[string]:string}但仍然出现相同的错误。 – modernator