You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classX{constructor(publicreadonlycurrentCost: number){}publicupdate(cost: number){returnnewX(this.currentCost+cost);}}constcost={cost: 5};constx=newX(5);x.update(-cost);// Should errorx.update(cost*-1);// Errors correctly
π Actual behavior
I refactored some code from returning a number to returning an object. I expect TypeScript to point me to all the places where I needed to make adjustments and came across one where I had -cost where cost was changed from a number to an object. TypeScript was not giving me an error like it does when I use cost * -1.
π Expected behavior
I would expect TypeScript to prevent implicit casts on non number types (or non-scalar types in case there are valid use cases of this for boolean/strings) if a PrefixUnaryExpression is used. There are some fun JavaScript things that can be done by using -[] or -{}, it is almost never what a developer intents.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
prefixunaryexpression
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/MYGwhgzhAEAa0G8BQ1rAPYDsIBcBOArsDungBQAOBARiAJbDR4CmYAJliAJ5oF4uYcAYXS4AXNEwEAttWZ4AlIgC+SFNCq0G0AhTZgczMhnGSZcxYnWoWOPpknMA7nDI4AFnQgA6YHwHCojjQANRoQQoA3OqqqkgY2MEmwQC8iMkSAKzK0fFYuNAAHtBpmM6umVFqhd66+oZkALTJVWptbTV1BkbJ0ABU0I0AjFFAA
π» Code
π Actual behavior
I refactored some code from returning a number to returning an object. I expect TypeScript to point me to all the places where I needed to make adjustments and came across one where I had
-cost
wherecost
was changed from a number to an object. TypeScript was not giving me an error like it does when I usecost * -1
.π Expected behavior
I would expect TypeScript to prevent implicit casts on non number types (or non-scalar types in case there are valid use cases of this for boolean/strings) if a PrefixUnaryExpression is used. There are some fun JavaScript things that can be done by using
-[]
or-{}
, it is almost never what a developer intents.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: