Microsoft/TypeScript
View on GitHubObject.defineProperty(variable) does not error in `.js` files if `variable` does not exist
Open
#61,165 opened on Feb 12, 2025
BugDomain: JavaScriptHelp Wanted
Description
🔎 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
💻 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