可以说,您正在编码一个从外部API接收输入的函数MyAPI。
该外部API MyAPI的合同规定其将返回string或number。
它是推荐的防范之类的东西null,undefined,boolean等即使它不属于API的一部分MyAPI?特别是,由于您无法控制该API,因此无法通过诸如静态类型分析之类的方法来做出保证,因此,安全起来总比对不起好。
我在考虑稳健性原则。
<!doctype html><html><head><title>504 Gateway Timeout</title></head><body>The server was unable to process your request. Make sure you have typed the address correctly. If the problem persists, please try again later.</body></html>