Typescript Node The operand of a 'delete' operator must be optional. Ts(2790)error
Closed this issue ยท 4 comments
System (please complete the following information):
- OS: macos
- node v12.19.0
- typescript 4.1.3
Describe the bug
when i making a simple post on my node aplication i recibe the request body i making a normal post for a user so when i take all the user data and i execute a save before i send my json i have to delete the password for use in the get so is when the bug appears in a message: "{
"resource": "/Users/dariocoronel/Desktop/practices/Gostack/gobarber/backend/src/routes/users.routes.ts",
"owner": "typescript",
"code": "2790",
"severity": 8,
"message": "The operand of a 'delete' operator must be optional.",
"source": "ts",
"startLineNumber": 24,
"startColumn": 20,
"endLineNumber": 24,
"endColumn": 33
}"
To Reproduce
Steps to reproduce the behavior:
- create a simple normal post in a node with express
- get all the request body data then save it to the basedata
- when you try to send a json with this that but you want delete user password before send all the data to a get for a list
- See error "The operand of a 'delete' operator must be optional."ts(2790) [24.20]
Expected behavior
i want to solve this problem
Screenshots or error log
here we can see clarily how the bug appears
Additional context
someone can helpme please
Hi, this is a typescript specific feature which is better asked on stack overflow than here, but as I was curious, I searched up the error and here is the solution. Hope it helps ๐ https://stackoverflow.com/questions/63702057/what-is-the-logic-behind-error-the-operand-of-a-delete-operator-must-be-opti
Thanks, i'm a new programer sorry for making my question on the wrong place, i gonna use more stackoverflow i didn't know anything jet about this incredible world! thanks!
I think this is perfectly fine @dariocoroneldev. It is all about learning and growing.
I found my solution because of you. Thank you
Hi, this is a typescript specific feature which is better asked on stack overflow than here, but as I was curious, I searched up the error and here is the solution. Hope it helps ๐ https://stackoverflow.com/questions/63702057/what-is-the-logic-behind-error-the-operand-of-a-delete-operator-must-be-opti
FYI, the link only mentions how to workaround the problem, but it does not explain why the error exists in the first place. If you are casting something with as
, of course the problem goes away, but that does not fix the underlying problem. Well, whether you care about the error is a different issue though and you may be perfectly fine with just bypassing it.