Open
Description
TypeScript Version: 2.6.1
Code
let func = () => "func";
+func; // no error
-func; // no error
let obj = { foo: "bar" };
+obj; // no error
-obj; // no error
Expected behavior:
Unary +
or -
is only applicable to a number
or maybe a string
. I would expect the lines listed as // no error
to be errors.
Actual behavior:
Unary +
and -
never generates a warning no matter what crazy stuff I try to apply it to.
I was made aware of this behavior by a recent Stack Overflow question. I see from #7019 that unary +
and -
on string
s is supported, and I guess I can understand that as a way to parse a string
into a number
(for +
, anyway. Is -
really used like this in practice?). But functions? objects? Seems more likely to be an error than intentional to me. Thoughts?