Microsoft/TypeScript
在 GitHub 查看Object.defineProperty(variable) does not error in `.js` files if `variable` does not exist
Open
#61,165 建立於 2025年2月12日
BugDomain: JavaScriptHelp Wanted
倉庫指標
- Star
- (48,455 star)
- PR 合併指標
- (平均合併 6天 17小時) (30 天內合併 9 個 PR)
描述
🔎 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