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
Argument of type '{ a: boolean; }' is not assignable to parameter of type 'A'.
Types of property 'a' are incompatible.
Type 'boolean' is not assignable to type 'string'.
The text was updated successfully, but these errors were encountered:
tinganho
changed the title
Definite assignments assertion doesn't work on object-short hand syntax
Definite assignment assertion doesn't work on object-short hand syntax
Apr 3, 2018
This is not a definite assignment assertion. That's a misplaced non-null assertion. There's a parse error at the exclamation mark. Everything is working as expected, only the assignability error is a bit misleading.
You just need to write it as {a: a!}.
#13035 already tracks type assertions on shorthand properties.
last time we talked about assertions, it seemed like a good idea to allow them. i do not think this is specifically different.
I think the bug here is a parsing bug. we parsed it as a uniary prefix expression instead of a unary postfix expression. and hence the boolean type.
TypeScript Version: 2.7.0-dev.201xxxxx
Search Terms:
definite assignment assertion object shorthand
Code
Expected behavior:
No error
Actual behavior:
Playground Link:
http://www.typescriptlang.org/play/#src=interface%20A%20%7B%0A%20%20%20%20a%3A%20string%3B%0A%7D%0A%0Alet%20As%3A%20A%5B%5D%20%3D%20%5B%5D%3B%0Alet%20a%3A%20string%20%7C%20undefined%20%3D%20'ff'%3B%0A%0Afunction%20f()%20%7B%0A%20%20%20%20As.push(%7B%20a!%20%7D)%3B%20%2F%2F%20Error%0A%7D
Related Issues:
The text was updated successfully, but these errors were encountered: