0
我最近將Flow應用於我的React Native項目。到目前爲止,大多數事情都是可以滿足的。使用Flow類型檢查調用連續可空對象的方法
let player ?Object = new Player();
if (this.player) {
this.player.stop();
this.player.destroy();
this.player = null;
}
但是,Flow希望我能像下面那樣。
let player ?Object = new Player();
if (this.player) {
this.player.stop();
}
if (this.player) {
this.player.destroy();
}
this.player = null;
有沒有適當的方法來處理這種情況?我不想在這裏使用壓制評論,因爲它不是一個特例。
https://flowtype.org/try/#0MYGwhgzhAEAK4E8CmAnA3gXwFCkjAgtGltNAA6KoBcA-NAPIBGAVksAC7QC80AdkgHc4lFAAoAlAG4S0ALYSiM0iCScKYZCm7R2ACwCWEAHTrN00qX0AzaKNOpxiixfsojEdgHsyE88-IiRgAmSB4ongi+Si4i2rwAriAgfqTYqVgYQA –
'讓玩家對象=新播放器()'應該是'讓球員:??對象=新播放器()' –