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.

Make Javascript intellisense detect inheritance

See original GitHub issue

From @benjaminmillhouse on December 21, 2016 17:33

  • VSCode Version: Code 1.8.0 (38746938a4ab94f2f57d9e1309c51fd6fb37553d, 2016-12-13T17:38:28.425Z)
  • OS Version: Darwin x64 16.3.0
  • Extensions:
Extension Author Version
JSDocTagComplete HookyQR 0.0.2
html-css-class-completion Zignd 1.0.3
theme-atom-one-dark andischerer 0.0.1
vscode-eslint dbaeumer 1.1.0
docthis joelday 0.3.5
Angular1 johnpapa 0.1.16
Angular2 johnpapa 1.0.2
csharp ms-vscode 1.5.3
js-atom-grammar ms-vscode 0.1.10
vscode-icons robertohuertasm 4.0.2
bootstrap-3-snippets wcwhitehead 0.0.8

Hello, I would love it if VS Code’s Javascript intellisense was able to detect inheritance. Please let me know if there is a way to accomplish this today through jsdoc comments or anything like that. I have tried all kinds of different ways to get VS Code to detect it (definitions like below, @augments, @extends jsdoc comments, etc) and have not gotten anything to work.

As an example, when inheriting like this:
function BaseClass() {
  this.foo = 'bar';
}
BaseClass.prototype.baz = function () { }

function InheritedClass() {
  BaseClass.call(this);
}
InheritedClass.prototype = Object.create(BaseClass.prototype);
InheritedClass.prototype.constructor = InheritedClass;

Would like the intellisense for new InheritedClass(). to show ‘foo’ and ‘baz’ as properties/methods for InheritedClass in Intellisense.

Copied from original issue: Microsoft/vscode#17690

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:13
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
trusktrcommented, Apr 13, 2021

JSDoc is not supported inside .ts files, so @constructor and @augments… don’t do anything in… .ts files. LOL

What can community members do to encourage ES5 support? Can we donate money towards particular issues? There has to be some way to get these things prioritized.

1reaction
adschmcommented, Aug 6, 2021

Thanks @Obscerno for this pointer. This is a derived option which does not need require to edit the file during build, but will produce some useless JS code eventually (though the code is never executed):

    function Child(arg) {
        Parent.call(this, arg);
        
        // Dummy section to initialize properties from superclass
        
        // eslint-disable-next-line
        if (false) {
                // @ts-ignore
                var dummy = new Parent(null);
                this.hello = dummy.hello;
        }

        // New code goes below . . . 
    }

Fortunately, TypeScript is broken enough so 1. the definitions are picked up inside the dead block and 2. one ts-ignore is enough even if you have multiple lines inside the block. (The latter is quite helpful since the silly ts-ignore has no options or block-treatment. Unbelievable …)

Edit/Update:

  1. Maybe one can even remove this dead condition with a good minimizer (I’m using WebOptimizer for ASP Core which does not).
  2. The if(false) hack does not work for function calls which are directly in the constructor:
    function Child(arg) {
        Parent.call(this, arg);
        
        // Dummy section to initialize properties from superclass
        
        // eslint-disable-next-line
        if (false) {
                // @ts-ignore
                var dummy = new Parent(null);
                this.hello = dummy.hello;
        }

        // New code goes below . . . 

        this.hello("abc"); // This will trigger: TS2722: Cannot invoke an object which is possibly 'undefined'

        this.anotherFunction = function() {
                this.hello("def"); // This triggers no warning and has correct type/Intellisense comment
        }
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

IntelliSense - 'this' not inherit objects on Javascript
IntelliSense - 'this' not inherit objects on Javascript ... I notice this image the IntelliSense should automatically recognize the content ...
Read more >
Two ways you can take advantage of types in JavaScript ...
This blog post describes how you can enable javascript intellisense and design time error highlighting without TypeScript.
Read more >
User and Workspace Settings - Visual Studio Code
To check which settings you have configured, there is a @modified filter in the Search bar. A setting shows up under this filter...
Read more >
C# IntelliSense - Visual Studio (Windows) - Microsoft Learn
Interfaces and base classes: IntelliSense automatically removes items from the interface and base class completion lists, in both class ...
Read more >
How To Make Vscode To Autocomplete Prototypal Inherited ...
html-css-class-completion, Zignd, 1.0.3 I would love it if VS Code's Javascript intellisense was able to detect inheritance. Please let me { BaseClass.call(this); ...
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