Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

A wrong (and now fixed) code in our app triggered this error :

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

But Javascript completely allows setting free properties on a string variable. I just tried it in Chrome console :

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

And it works perfectly.

So in which context do the JS interpreter trigger this error ?

The original code is written in Typescript, then transpiled with Babel. This is a runtime error. I assume this is not related to typescript since other people report a similar runtime error, ex. here and here

like image 992
Offirmo Avatar asked May 23 '16 14:05

Offirmo


1 Answers

So in which context do the JS interpreter trigger this error ?

Strict mode.

'use strict';
'BAR'.FOO = 'test';
like image 164
meagar Avatar answered Sep 22 '22 03:09

meagar