-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow arithmetics on class/objects with valueOf method #5337
Comments
I also tried this one (defining a variable with the Number interface), and got the same right-hand side error message: let X: Number = new LOL(10);
let Y: Number = new LOL(7);
alert(X * Y); |
I must define |
This works on runtime but you can get a compiler error:
I guess by design. |
@xLama yeah, of course. I was just experimenting with it, to see if there is a way to stop that compiler warning/error. The other example works on runtime, but the TypeScript compiler complains about it |
@Zorgatone But I don´t know why fails because ES lets it. Maybe a Microsoft employee can explain us. I think it should work to align with ECMA. |
It's just a warning/error from Typescript, but the generated code is correct and executes fine on runtime (first example only). I know the second example will never work, it was a test |
See #2361 |
Both of the two examples below won't work, and I get a compiler error/warning: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.".
Example 1 (defining method valueOf and implementing Number interface) working on runtime:
Example 2 (extending Number "class") Runtime Error: "Uncaught TypeError: Number.prototype.valueOf is not generic"
The text was updated successfully, but these errors were encountered: