0

This is my code. I am getting id of each coach, participant and explanation and putting them in array. It is working but the same time throws errors such as

Property 'id' does not exist on type 'never'. Property 'name' does not exist on type 'never'.

In both functions 'id' and 'name' same error. In my chooseName function 'id' does not exist in starting from line 4 and 'name' in line 7

I would appreciate any help! The app is on

Ionic:

Ionic CLI : 6.16.1 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.6.7 @angular-devkit/build-angular : 0.901.15 @angular-devkit/schematics : 11.2.13 @angular/cli : 11.2.13 @ionic/angular-toolkit : 2.3.3

Cordova:

Cordova CLI : 10.0.0

      chooseName(event){
    console.log(event)
    this.challenge.coach_names = [];
    this.coaches.findIndex(x => x.id === event.detail.value[0])
    console.log(this.coaches[this.coaches.findIndex(x => x.id === event.detail.value[0])])
    for (var coach of event.detail.value) {
      console.log((this.coaches[this.coaches.findIndex(x => x.id === coach)]))
      this.challenge.coach_names.push(this.coaches[this.coaches.findIndex(x => x.id === coach)].name)
      }
      console.log(this.challenge.coach_names)
}

  chooseParticipant(event){
    console.log(event)
    this.challenge.participant_names = [];
    this.participants.findIndex(x => x.id === event.detail.value[0])
    console.log(this.participants[this.participants.findIndex(x => x.id === event.detail.value[0])])
    for (var participant of event.detail.value) {
      console.log((this.participants[this.participants.findIndex(x => x.id === participant)]))
      this.challenge.participant_names.push(this.participants[this.participants.findIndex(x => x.id === participant)].name)
      }
      console.log(this.challenge.participant_names)
}
Namo
  • 1
  • 1
  • What is the line that throw this error ? Is it an error during the build or runtime ? – Marco Jun 02 '21 at 08:55
  • 1
    Sorry for not being clear. Property 'id' does not exist on type 'never'. in line this.participants.findIndex(x => x.id === event.detail.value[0]) Property 'id' does not exist on type 'name'. in this.challenge.participant_names.push(this.participants[this.participants.findIndex(x => x.id === participant)].name) Same for chooseName – Namo Jun 02 '21 at 09:01
  • Does the error appear during runtime ? – Marco Jun 02 '21 at 09:06
  • yes, it appeared during runtime. But now i have it even when not running – Namo Jun 02 '21 at 09:11
  • Items in the `coaches` array are not initialized correctly. Can you show how you populate this array ? – Marco Jun 02 '21 at 09:17
  • in my ts public coaches: []; when retrieving from object avatar: null city: null country: null id: "8880-6f9-43c6-8041-2c47" name: "Coach" subtype: "employee" type: "user" – Namo Jun 02 '21 at 09:38
  • Any idea what am I doing wrong? Thanks in advance! – Namo Jun 02 '21 at 11:22
  • Please update your question instead of adding it in comments, it will be more readable. I haven't understand how you populate your `this.coaches` array. But I think the problem is there. – Marco Jun 02 '21 at 15:26

0 Answers0