[英]Typescript Error TS2339: Property 'project' does not exist on type '{}'
[英]Typescript: Arrow function - TS2339: Property does not exist on type '{}'
使用Angular,在rxjs
流中使用fat arrow functions
時,經常會遇到typescript
編譯錯誤。
我仍然可以運行該應用程序,並且可以進行翻譯,但是我想知道如何擺脫該錯誤並了解它。
鑒於:
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)
我得到了錯誤:
[加載程序]文件中的錯誤。ts:xx:xx TS2339:類型'{}'上不存在屬性'prop1'。
[加載程序]文件中的錯誤。ts:xx:xx TS2339:類型'{}'上不存在屬性'param1'。
為什么抱怨呢?
試試這個:
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.