I have a api which return objects / array like this:
(2) [{...}, {...}] object
0: {a: '1', b: {id: '1'}}
1: {a: '2', b: {id: '2'}}
So it looks like array of objects (but debuges says 'Object').
So in my code I have:
return this.http.get(this.url).pipe(
map(datas => {
return datas.map(data => {
let object = {
a: data['a'],
b: data['b']['id'],
}
return object;
})
})
);
but there:
return datas.map(data => {
I got an error:
Property 'map' does not exist on type 'Object'.
But application is working well is correctly shows this data. But this error is annoying.
What can I do?
The "Property does not exist on type Object" error occurs when we try to access a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names.
map() is an inbuilt TypeScript function that is used to create a new array with the results of calling a provided function on every element in this array.
The error "Property does not exist on type 'never'" occurs when we try to access a property on a value of type never or when TypeScript gets confused when analyzing our code. To solve the error, use square brackets to access the property, e.g. employee['salary'] . Here is an example of how the error occurs.
The following operators were renamed in RXJS6
catch() => catchError()
do() => tap()
finally() => finalize()
switch() => switchAll()
Additionally, some Observable-creation methods were renamed/ refactored:
throw() => throwError()
fromPromise() => from() (this automatically detects the type)
FOR MAP syntax
import { map } from 'rxjs/operators';
myObservable
.pipe(map(data => data * 2))
.subscribe(...);
I had to specify the type of the return value with (data: any) => { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With