Mark

Mark

  • NA
  • 28
  • 14.5k

Cannot invoke an object which is possible undefined'

Nov 9 2021 6:44 PM

Here is the property and method

private errorMessages = new Map<string, () => string>();


public get errors(): Array<string> {
    if (!this.control) {
        return [];
    }

    const { errors } = this.control;
    return Object.keys(errors).map(key => this.errorMessages.has(key) ? 
  this.errorMessages.get(key)() : <string>errors[key] || key);
}

I get this error on this on this part of the code

this.errorMessages.get(key)()

Can someone explain why the problem as to why I'm getting this error and a possible solution to the problem?


Answers (1)