TypeError: Unable to create property "FOO" in string "BAR"

Wrong (and now fixed) code in our application caused this error:

TypeError: Cannot create property 'FOO' on string 'BAR'

But Javascript completely allows you to set free properties in a string variable. I just tried it in the Chrome console:

'BAR'.FOO = 'hello'
'BAR'['FOO'] = 'hello'

And it works great.

So, in what context does the JS interpreter trigger this error?

The source code is written in Typescript, then overflowed with Babel. This is the lead time . I assume this is not related to typescript, as other people report a similar runtime error, for example. here and here

+4
source share
1

, JS ?

.

'use strict';
'BAR'.FOO = 'test';
+11

All Articles