TS1068

Unexpected token. A constructor, method, accessor, or property was expected.

Broken Code ❌

class User {
  constructor(private firstName: string, private lastName: string) {
  }
 
  function getName() {
    return `${this.firstName} ${this.lastName}`;
  }
}

Fixed Code ✔️

Functions that are part of a class are being called "method". The method of a class is defined without the function keyword:

class User {
  constructor(
    private firstName: string,
    private lastName: string
  ) {}
 
  getName() {
    return `${this.firstName} ${this.lastName}`;
  }
}