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
Although we won't get runtime errors in this case, it may cause unpredictable result, e.g. "[[Object]]123", which is unexpected, so I think ts should not allow unknown types to concat with strings.
The text was updated successfully, but these errors were encountered:
Sorry I don't understand what symbol means here. The problem now is unknown type + number would get an error, but unknown type + string won't get an error.
So + with a string is very permissive, but not in the case of symbol. Given that something of type unknown could be a symbol, then the safe thing is to flag an error as you suggest. With symbol you will get a runtime error.
TypeScript Version: 3.3.0
Code
Expected behavior:
All the declarations of variables
b
c
d
should have errors.Actual behavior:
Only declaration of variable
b
have error.Playground Link:
https://www.typescriptlang.org/play/index.html#src=declare%20const%20a%3A%20unknown%3B%0Aconst%20b%20%3D%20a%20%2B%20123%3B%0Aconst%20c%20%3D%20a%20%2B%20'123'%3B%0Aconst%20d%20%3D%20%60%24%7Ba%7D123%60%3B%0A
Although we won't get runtime errors in this case, it may cause unpredictable result, e.g. "[[Object]]123", which is unexpected, so I think ts should not allow unknown types to concat with strings.
The text was updated successfully, but these errors were encountered: