Using Angular, I often get typescript
compile errors when using fat arrow functions
inside an rxjs
stream.
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 '{}'.
ERROR in [at-loader] file.ts:xx:xx TS2339: Property 'param1' does not exist on type '{}'.
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)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments