-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Object.defineProperty(variable) does not error in .js
files if variable
does not exist
#61165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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 |
as a fun twist, all of these do error: Object['defineProperty'](blah2, "name", { value: "default" })
Object.defineProperty(blah2, (void 0, "name"), { value: "default" })
Object.defineProperty(true ? blah2 : {}, "name", { value: "default" }) so i'm guessing something about the exact form EDIT: it also fails if the statement is not at the top level of a module |
Yeah, we treat |
@lubieowoce this is somewhat expected. Only the most straightforward static-ish patterns are supported by those special property assignments. |
wht u mean to say i am wrong at that point or what @Andarist |
|
This PR changes the server action generated code a bit to work around a typescript bug and remove some false positives we got while typechecking: microsoft/TypeScript#61165 The trick is that typescript seems to look for *exactly* `Object.defineProperty(obj, 'literal', { value: ... })`, and changing any part of the expression bypasses the bug, so we can just use `Object['defineProperty']` instead.
@sandersn do u have an opinion on how this should work and how |
In TS7, implicit namespace creation in JS is completely gone. And I'm not sure if/when |
π Search Terms
defineProperty, cannot find namee
π Version & Regression Information
defineProperty
β― Playground Link
https://www.typescriptlang.org/play/?noImplicitAny=false&strictFunctionTypes=false&strictPropertyInitialization=false&strictBindCallApply=false&noImplicitThis=false&noImplicitReturns=false&alwaysStrict=false&declaration=false&target=3&module=1&filetype=js&strictNullChecks=false#code/PTAEAEBcGcFoGMAWBTeBrAUCUBhRBDAOwHNlQAiAGyOPNEgHsKAVATwAdkBleAJwEt2kOv0IsuuBoQBm-WqAZD+U6PSYBbfGjL9IoZL14NeGAPIAjAFapIAOgAmyWYWQAFI516RWACnPVEABoKQnx1ZHJggG8AN3xKAFdkAC5yR2l8BMphYIB3AUh8fxSMymhkAF8ASiA
π» Code
π Actual behavior
No error in
.js
filesπ Expected behavior
Errors in
.js
files withTS2304: Cannot find name 'foo'.
Additional information about the issue
Full repro: https://github.com/eps1lon/tsc-object-define-property
The text was updated successfully, but these errors were encountered: