Skip to content
Advertisement

IntelliSense/JSDoc @param = @return, a.k.a. how do I document wrapper functions?

I have a function which takes in another function as an argument, does something to that function-argument, and then returns that same function-argument (or at least returns a function with the exact same signature to it)

JavaScript

However, as you can see from my comments in the following…

JavaScript

… IntelliSense will autocomplete when calling arbitraryFn() but not wrappedArbitraryFn().

Is there any way to get IntelliSense to dynamically autocomplete my wrapped functions with the same signature as their unwrapped counterparts, i.e. without having to explicitly re-document every newly-wrapped function?

Advertisement

Answer

I’m revisiting this again as I now have a (near-)perfect solution for my use-case. The reality is IntelliSense is far more TypeScript than it is standard JSDoc. As it turns out, you can leverage the @template tag to solve the above, and as far as I’ve seen, anything I can accomplish in TypeScript I can also accomplish in JavaScript IntelliSense:

The New Wrapper Function

JavaScript

Wrapping a Previously-Declared Function

JavaScript

Wrapping an inline Function

JavaScript

Only downside for me is the inline is a bit ugly, imo, but it works. However, do note that this may not be a valid solution for true/vanilla JSDoc. This solution is great if, like me, you don’t really use/care about JSDoc and you’re really just here for the IntelliSense piece.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement