microsoft / microsoft/TypeScript

JSDoc '@this' not actually used to enforce thisArg at callsite

Open
#42,239 2 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.