-
Notifications
You must be signed in to change notification settings - Fork 12.8k
+=
on string | undefined
should narrow its operand to string
#20203
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
Comments
we do not consider |
I don't mind how you treat this. |
We tried to talk about this but argued about implicit coercion for half an hour instead... |
@RyanCavanaugh what was the outcome of this argument? I feel like, at least in strict mode, typescript should disallow type coercion altogether. As it stands right now, it's quite inconsistent with what it lets through, e.g. const foo = 42 + {}; // Operator '+' cannot be applied to types '42' and '{}'.
const foo = '42' + {}; // fine
const foo = {} + []; // Operator '+' cannot be applied to types '{}' and 'never[]'.
const foo = `${{}}${[]}`; // fine |
+=
on string | undefined
should narrow its operand to string
IMO, template literals are "explicit enough" to not be considered coercion. But Recently, I noticed const NAME = 'foobar'
let chars = ''
chars += NAME[Math.random() * 0x10 | 0] because, |
TypeScript Version: 2.6.1
Code
Expected behavior:
Both notations should be equivalend
The text was updated successfully, but these errors were encountered: