是否可以从应用程序代码中的Flow对象类型定义中获取键(换句话说,是否以任何方式在运行时代码中实现了Flow类型定义)?
用例:
let fp = new fileUploadParametre();
let formData: FormData = new FormData();
var file;
if ($('#fileinput')[0] != undefined) {
if ($('#fileinput')[0].files.length > 0) {
file = $('#fileinput')[0].files[0];
formData.append('uploadingFile', file);
//fp.fileName = file.name;
console.log(formData);
}
formData.append('siparisid', this.siparis.siparisid);
formData.append('dokumantipi',this.form.controls.belgeTipiFormController.value);
formData.append('aciklama',this.form.controls.aciklamaFormController.value);
this.fileUploadService.kaydet(
formData
)
.subscribe(result => {
console.log(result);
if (result === true) {
this.errorMessages = [];
this.dialogRef.close(true)
}
else
this.errorMessages = ['Kayıt Yapılamadı'];
},
err => {
if (err.status == 0) {
this.errorMessages = ['Bağlantı hatası! sunucuya erişilemedi.'];
}
else if (err.status == 404) {
this.errorMessages = ['Bağlantı hatası! sunucuya erişilemedi.'];
}
else if (err.status == 401) {
this.errorMessages = ['Yetki Hatası.'];
}
else if (err.status == 400) {
let errBody = JSON.parse(err._body);
if (errBody
&& errBody['error'] == 'invalid_grant')
this.errorMessages = ['Oturum Açılamadı Geçersiz Kullanıcı veya Şifre'];
else
this.errorMessages = [errBody.message];
}
else
this.errorMessages = [err.statusTest]
}
);
}
**my Service**
public kaydet(
formData: FormData
): Observable<any> {
let postFiles = {
formData: formData
};
return this.http.post(
this.apiUrl + '/dokumanlar/ResimKaydet',
JSON.stringify(postFiles)
)
.map(res => res.json());
}
展开式结构(type Props = {
userID: string,
size: number | PhotoSize,
subscribePresence: Function,
unsubscribePresence: Function,
presenceStatus: ?PresenceStatus,
photoURL: ?string,
userName: ?string,
};
class Photo extends Component<Props> {
// ...
render() {
const { userID, size, presenceStatus } = this.props;
// Other props used elsewhere in the component
const restProps = _.omit(this.props, ???)
}
}
)不起作用,因为const { /* etc */ ... rest} = this.props
中还有其他道具未被使用。但是,我想要选择其他可能已指定的道具(render
,className
等)。
可以id
来源???
类似的内容吗?据我所知,类型定义被编译掉了,因此尝试在运行时代码中引用Object.keys(Props)
会引发Props
。
答案 0 :(得分:1)
Flow提供静态类型分析,所有Flow代码在运行时被剥离(流注释不是有效的Javascript代码)。
要实现您的目标,您需要在删除Flow代码后获得有关预期道具的信息。您可以通过为组件中的所有道具设置defaultProps然后编写:
来实现const restProps = _.omit(this.props, Photo.defaultProps)
无论如何,设置defaultProps通常都是一个好主意。