简体   繁体   English

打字稿:箭头功能-TS2339:类型“ {}”上不存在属性

[英]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.

相关问题 打字稿错误TS2339:类型“ {}”上不存在属性“项目” - Typescript Error TS2339: Property 'project' does not exist on type '{}' 为什么 TypeScript 会抛出错误:TS2339:“EventTarget”类型上不存在属性“错误” - Why does TypeScript throw the error: TS2339: Property 'error' does not exist on type 'EventTarget' 打字稿错误TS2339:'Window'类型中不存在属性'webkitURL' - Typescript error TS2339: Property 'webkitURL' does not exist on type 'Window' 错误TS2339:类型“无效”上不存在属性“ _ws” - error TS2339: Property '_ws' does not exist on type 'void' 错误 TS2339:属性“Connection”在类型“Navigator”上不存在 - Error TS2339: Property 'Connection' does not exist on type 'Navigator' 错误TS2339:类型“ {}”上不存在属性“ hometeam” - error TS2339: Property 'hometeam' does not exist on type '{}' 错误 TS2339:“订阅”类型上不存在属性“订阅” - error TS2339: Property 'subscribe' does not exist on type 'Subscription 错误 TS2339:属性“flatMap”在类型“any”上不存在 - error TS2339: Property 'flatMap' does not exist on type 'any 错误 TS2339:“响应”类型上不存在属性“结果” - error TS2339: Property 'results' does not exist on type 'Response' TS2339:类型“{}”上不存在属性“文本” - TS2339: Property 'text' does not exist on type '{}'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM