[英]Typescript: Arrow function - TS2339: Property does not exist on type '{}'
Using Angular, I often get typescript
compile errors when using fat arrow functions
inside an rxjs
stream. 使用Angular,在
rxjs
流中使用fat arrow functions
时,经常会遇到typescript
编译错误。
I can still run the app and it does transpile, but I would like to know how to get rid of the error and understand it. 我仍然可以运行该应用程序,并且可以进行翻译,但是我想知道如何摆脱该错误并了解它。
Given: 鉴于:
this.data$ = this.route.params
.switchMap(params =>
Observable.forkJoin([
Observable.of(params),
this.http.get('/api', { param1: params.param1, param2: params.param2 })
])
//**Errors from this part below**
.map(([params, data]) => data.prop1 + ' - ' + params.param1)
I get the errors: 我得到了错误:
ERROR in [at-loader] file.ts:xx:xx TS2339: Property 'prop1' does not exist on type '{}'.
[加载程序]文件中的错误。ts:xx:xx TS2339:类型'{}'上不存在属性'prop1'。
ERROR in [at-loader] file.ts:xx:xx TS2339: Property 'param1' does not exist on type '{}'.
[加载程序]文件中的错误。ts:xx:xx TS2339:类型'{}'上不存在属性'param1'。
Why does it complain about this? 为什么抱怨呢?
Try this one: 试试这个:
this.data$ = this.route.params
.switchMap((params: any) =>
Observable.forkJoin([
Observable.of(params),
this.http.get('/api', { param1: params.param1, param2: params.param2 })
])
//**Errors from this part below**
.map(([params, data]: [any, any]) => data.prop1 + ' - ' + params.param1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.