Currently, I am working on a small application using Ionic 3 to query a Firebase database for two sets of data. Initially, I encountered an error during the first build stating "Property does not exist on type '{}'", however, after saving the .ts file again (for example, home.ts to trigger an Ionic rebuild), the error disappeared and the page functioned as expected.
The code snippet I am using is as follows:
ionViewDidLoad() {
this.db.list('myPath-in-firebase', ref => ref.orderByChild('my-key'))
.valueChanges()
.subscribe(result => {
let mydata1 = result.map(x => x.my-property-key1);
let mydata2 = result.map(x => x.my-property-key2);
console.log(mydata1);
};
}
Upon the first build after running 'ionic serve', I am encountering a TypeScript error: "Property 'my-property-key1' does not exist on type '{}'. However, as mentioned earlier, saving the project file triggers an Ionic rebuild, resolving the issue. I suspect that I need to declare 'x' and its properties somewhere, but I am unsure of how and where to do so.
For context, the structure of my Firebase database is as follows:
my-firebase-database
|- my-Path
|- Push-ID-1
|- my-property-key1: value
|- my-property-key2: value
|- Push-ID-2
|- my-property-key1: value
|- my-property-key2: value
|- Push-ID-3
|- my-property-key1: value
|- my-property-key2: value
My goal is to have two arrays, one containing values of 'my-property-key1' and the other with values of 'my-property-key2'. Any assistance you can provide would be greatly appreciated.
Update: Refer to the comments for the workaround I used, changing the syntax from result.map(x => x.my-property-key1) to result.map(x => x[my-property-key1]).
For further details, please visit: https://github.com/Microsoft/TypeScript/issues/12596