microsoft / microsoft/TypeScript
JSDoc '@this' not actually used to enforce thisArg at callsite
Open
Nobody has claimed this yet.
Bug
Domain: JSDoc
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🔎 Search Terms
JSDoc this
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
@this
⏯ Playground Link
Playground Link: Provided
💻 Code
/** @this {string} */
export function firstCharOfThis() {
return this.charAt(0);
}
firstCharOfThis(); // invalid
firstCharOfThis.call(1); // invalid
firstCharOfThis.call('foo'); // valid
🙁 Actual behavior
No compile error, but a runtime error.
🙂 Expected behavior
First two calls should be an error, last call should be fine. Expected the same behavior as if it was written in TS with an explicit this-parameter
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 TypeScript Playground reproduction and compare the JSDoc @this function with an equivalent explicit this-parameter declaration. The fix is complete when calling firstCharOfThis() and firstCharOfThis.call(1) produces errors while firstCharOfThis.call('foo') remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100