首页 > 解决方案 > 为什么以下方法不给出语法错误?

问题描述

// There are three possible booleans available this.oneBoolean, this.otherBoolean and this.thirdBoolean not used in the scope of this method
canEditSomething(): boolean {
   if(this.oneBoolean) {
     return true
    }
   if (this.otherBoolean) {
     return false
   }
}

所以问题是如果上面的 if 条件都不满足,编译器或更准确地说是编译器在返回之前是否在方法范围的末尾添加了默认返回语句?

标签: typescript

解决方案


推荐阅读