Search code examples
javascriptintellisensees6-proxy

Documenting functions built by a Proxy get trap


In https://github.com/draber/fancy-node/blob/main/src/index.js#L242 I use the get trap of a Proxy to build function names on the fly. That works just fine, but the problem is documentation. I'd like to have IntelliSense in VS Code for instance, but I have no idea on where to start. I'd be grateful for any pointers.


Solution

  • In case somebody comes with a similar problem in the future, I have found a solution. In my particular scenario I know the names and signatures of all "virtual", i.e. Proxy-generated functions.

    A file index.d.ts with all function declarations in the same directory where index.js (the main entry point) lives solves the issue. VS code uses this file for IntelliSense but it won't appear in the bundle, so that the file size doesn't change.