Home > Back-end >  This expression is not callable. Type 'String' has no call signatures ts(2349)
This expression is not callable. Type 'String' has no call signatures ts(2349)

Time:10-12

I have the following class:

class User {
    private _email: string;
    
        public get email(): string {
            return this._email;
        }
        public set email(value: string) {
            this._email = value;
        }
    }
      
    
      export {User};

I would like to log the user's email, but I can't pass a string parameter throught the function, because it occurs "This expression is not callable. Type 'String' has no call signatures" problem

function App() {

  const user = new User();
  user.email("[email protected]");
}
export default App;

What can I do differently here? Thanks in advance

CodePudding user response:

This is a js problem before being Typescript problem.

You need to understand getters and setters

To fix the issue, you can:

  const user = new User();
  user.email = "[email protected]"; // to set the value 
  console.log(user.email) // to read
  • Related