在VSCode的源文件中,有一些具有特定返回类型规范的函数,例如:
export function isString(str: any): str is string {
if (typeof (str) === _typeof.string || str instanceof String) {
return true;
}
return false;
}
我想知道“str is string”的目的是什么,而不只是写成“boolean”。
我们可以在其他情况下使用“str is string”之类的吗?
function isPoint3D(obj: any): obj is Point2D
。难道不应该是obj is Point3D
吗? - Oygen87