Microsoft/TypeScript

Object.defineProperty(variable) does not error in `.js` files if `variable` does not exist

Open

#61.165 aperta il 12 feb 2025

Vedi su GitHub
 (9 commenti) (2 reazioni) (0 assegnatari)TypeScript (6726 fork)batch import
BugDomain: JavaScriptHelp Wanted

Metriche repository

Star
 (48.455 star)
Metriche merge PR
 (Merge medio 6g 17h) (9 PR mergiate in 30 g)

Descrizione

🔎 Search Terms

defineProperty, cannot find namee

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about 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

// javascript.js
// @ts-check
// Does not error unless in `.ts` file.
Object.defineProperty(foo, "name", { value: "default", writable: false });

🙁 Actual behavior

No error in .js files

🙂 Expected behavior

Errors in .js files with TS2304: Cannot find name 'foo'.

Additional information about the issue

Full repro: https://github.com/eps1lon/tsc-object-define-property

Guida contributor