在angular引入新的HttpClient之前,我们从http api调用返回的对象可以使用instanceof
关键字进行验证。但是,在使用HttpClient模块后,不能再这样验证了。我正在尝试一些简单的方法,但类型检查每次都返回false。
期望的行为是:
```
getCow() {
return this.http.get<Cow>(ApiRoute.GET_COW, options)
.map(res => res as Cow)
.toPromise()
.then((c: Cow) => {
console.log(c instanceof Cow); //this is false
})
}
```
would return true. does anyone know of a simple way to new up an instance behind the scenes of the http client?
返回true。有没有人知道在Http客户端背后创建一个实例的简单方法?
new
来构建它,并用cow
属性进行初始化。这不是 Angular 或 TS 可以为你处理的东西。 - Estus Flaskres
包含什么?这意味着它可以被丢弃吗? - Estus Flask