microsoft / microsoft/TypeScript
Object.defineProperty(variable) does not error in `.js` files if `variable` does not exist
Open
Nobody has claimed this yet.
Bug
Domain: JavaScript
Help Wanted
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided javascript.js reproduction and TypeScript Playground link, then trace JavaScript checking for Object.defineProperty when @ts-check is enabled. Compare the .js and .ts behavior and identify the relevant checker path. Done means the JavaScript example reports TS2304 for foo and has regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100