TS2663

Cannot find name 'firstName'. Did you mean the instance member 'this.firstName'?

Broken Code ❌

class Person {
  get firstName(): string {
    return firstName;
  }
}

Fixed Code ✔️

If you want to use a getter, you need to back it up with a private property:

class Person {
  private _firstName: string = '';
 
  get firstName(): string {
    return this._firstName;
  }
}

Starting from TypeScript 4.9, you can also use an auto-accessor field:

class Person {
  accessor firstName: string = '';
}