Operating a delete operator needs to be optional

Asked

Viewed 366 times

-2

I set up a Node server, and when I went to do the tests to get up to production I saw that Eslint was accusing me of an error:

Erro expresso no Eslint

Just for the record, it’s working as due, delete is removing the property of the object, however, I can’t pass the Eslint test and others, such as github itself because of this error. I wanted to know what would be the best practice, for the use of delete in this case.

1 answer

2


Simple, because if you remove the property of an interface that is not optional, as the error is, the user interface would no longer be a user interface because lint understands that you would need that property for the interface work. The easiest way to solve is to mark the property as optional in the interface:

interface User {
  password?: string;
}

That way lint understands that the interface can, or does not need to, contain the password so that work, but without saying that the property can be passed null, see more about optional properties.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.