question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Contextual 'this' parameter in JSDoc doesn't show correct completions after property assignment on `this` in function-valued object literal property

See original GitHub issue

Bug Report

🔎 Search Terms

  • js this type
  • js this function property
  • function property this type

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about “Functions”

⏯ Playground Link

N/A - involves JS code which cant be emulated in playground at the moment

💻 Code

Below are some examples of the issue including the tsconfig.json and the code. The code comments describe what suggestions the intellisense provide, and here is what is expected, ie the types showing up on this as defined in the ts file:

image

The issue is below, where if the function assigns any property to this then the intellisense for this is limited to those assigned properties and ignores the defined type, e.g.:

image

🙁 Actual behavior

If the function assigns any property to this then the intellisense for this is limited to those assigned properties and ignores the defined type.

🙂 Expected behavior

The issue above seems to only be for function properties with function declarations ie {property: function() {...}} if the function property uses shorthand ie {property() {...}} then the expected behaviour occurs regarding the typing of this, ie there is intellisense based on the defined type of this regardless of what happens in the function (from what I have tried).

For example: image

From my understanding the function declaration and shorthand notations shouldnt have different behaviour according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions, so the typing also shouldnt behave differently.

Turning on checkJs fixes the issue however it means migrating to TS is more difficult as all the issues need to be fixed before getting any of the benefits e.g. intellisense, and this also limits functionality for large code bases migrating to TS but with a lot of legacy JS code.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

Object literal property assignment doesn't get contextual type ...
Object literal property assignment doesn't get contextual type from @type jsdoc #43379 ... Fix Available A PR has been opened for this issue...
Read more >
Use JSDoc: @param
Documenting a parameter's properties /** * Assign the project to an employee. * @param {Object} employee - The employee who is responsible for...
Read more >
JSDoc Reference - TypeScript: Documentation
The list below outlines which constructs are currently supported when using JSDoc annotations to provide type information in JavaScript files.
Read more >
Why does this object literal not render to JSDoc?
I run JSDocs 3.3.0-beta3 with private: true in a grunt task but on the modules page there are no private methods or arguments...
Read more >
An introduction to JSDoc - 2ality
Variable : The term variable in JSDoc often refers to all documentable entities which include global variables, object properties, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found