Inconsistency between element access and object destruction #59571
Labels
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
π Search Terms
destruct object
π Version & Regression Information
Before
v4.4.4
, index expression in element access was also not inferred as const. So this issue starts fromv4.4.4
. Reproducible in Nightly build.β― Playground Link
https://www.typescriptlang.org/play/#code/DYUwLgBAdhC8EEYIEMDOEDGB7KqwChtdIs4IBvFBALggCIE6V0i8IBffQnNgDzKwBtAAbIAJOSjthAXXwB6eRGUQAegH5uxChBHjJ0mbQCeHAfiA
π» Code
π Actual behavior
`a${n}`
in object destruction not inferred as const ("a1"
)π Expected behavior
`a${n}`
in object destruction should be inferred as"a1"
, just like the one in element access.Additional information about the issue
A possible workaround is to add
as const
after`a${n}`
. I think the main problem is the inconsistency between element access and object destruction, which is confusing.The text was updated successfully, but these errors were encountered: