我在我的代码中遇到了这个错误,我觉得它应该被Lint或TypeScrip本身纠正.有没有什么插件/附加设置可以设置为使"默认返回"成为编译警告?
我写的内容:
activeRegion = regions.find( region => { region.countryCode === activeCountryCode } )
我应该写的是:
activeRegion = regions.find( region => region.countryCode === activeCountryCode )
第二个函数执行您想要的操作,并返回条件为真的区域.
第一个函数,因为您实际编写了一个函数,所以需要返回.但由于JS有默认回报的概念,它实际上变成了这样
activeRegion = regions.find( region => {
region.countryCode === activeCountryCode
return undefined;
} )
当然,在这种情况下,哪些是无稽之谈(什么都找不到),那么有没有一条LINT规则可以阻止这些偷偷摸摸的默认回报被添加进来?