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
{{ message }}
Repository navigation
Object.defineProperty(variable) does not error in .js files if variable does not exist #61165
assin it to me let me solve this it is beacuse TypeScript treats undefined variables more loosely in JavaScript files unless strict rules are applied.so i can solve this by doing easiest fix is to ensure foo is defined before usage
Janka Uryga (@lubieowoce) this is somewhat expected. Only the most straightforward static-ish patterns are supported by those special property assignments.
Nathan Shively-Sanders (@sandersn) do u have an opinion on how this should work and how file.jsGlobalAugmentations should be utilized (should they perhaps depend on checkJs or something)?
In TS7, implicit namespace creation in JS is completely gone. And I'm not sure if/when Object.defineProperty special handling will be added either. Either way, there should be an error on foo in the original example.
Activity
mohityadav8 commentedon Feb 12, 2025
assin it to me let me solve this it is beacuse TypeScript treats undefined variables more loosely in JavaScript files unless strict rules are applied.so i can solve this by doing easiest fix is to ensure foo is defined before usage
lubieowoce commentedon Feb 12, 2025
as a fun twist, all of these do error:
playground
so i'm guessing something about the exact form
Object.defineProperty(obj, 'literal', { ... })hits some special handling and causes the bug.EDIT: it also fails if the statement is not at the top level of a module
RyanCavanaugh commentedon Feb 12, 2025
Yeah, we treat
Object.defineProperty(x, "prop")as a synthetic declaration ofx.propwhich (implicitly! bad!) creates the parentxdeclarationAndarist commentedon Feb 13, 2025
Janka Uryga (@lubieowoce) this is somewhat expected. Only the most straightforward static-ish patterns are supported by those special property assignments.
mohityadav8 commentedon Feb 13, 2025
wht u mean to say i am wrong at that point or what Mateusz Burzyński (@Andarist)
Andarist commentedon Feb 13, 2025
foogets added tofile.jsGlobalAugmentationssymbol table and that gets merged with globals. This mechanism was introduced in #26918fix: workaround for TS bug in Object.defineProperty (#75944)
Andarist commentedon Feb 25, 2025
Nathan Shively-Sanders (@sandersn) do u have an opinion on how this should work and how
file.jsGlobalAugmentationsshould be utilized (should they perhaps depend oncheckJsor something)?sandersn commentedon Apr 14, 2025
In TS7, implicit namespace creation in JS is completely gone. And I'm not sure if/when
Object.definePropertyspecial handling will be added either. Either way, there should be an error onfooin the original example.DetachHead commentedon Mar 12, 2026
why does it do that? is there an option to disable this behavior?