readmeio/api

CJS/JS intellisense suggestions doesn't align with actual types

kanadgupta opened this issue · 3 comments

Node version: v16.14.0
npm version: 8.3.1

  1. Create a new directory, run npm init -y
  2. Install and set up using our spec, then select JS + CJS options in prompts:
npx api@latest install @developers/v2.0#452hs23laswqxqy
  1. Create a new file called index.js, note that when you bring up intellisense1 when importing the package, it suggests using .default:

CleanShot 2022-12-06 at 09 59 34@2x

And if you keep using intellisense, you'll notice that readme.default. starts suggesting functions:

CleanShot 2022-12-06 at 10 01 06@2x

If you continue using intellisense to populate a function and then attempt to run it, you'll run into a TypeError:

CleanShot 2022-12-06 at 10 04 06@2x

The fix here is to remove the .default and it works as expected, but then Intellisense isn't nearly as helpful unless you know the exact method to use. Here's a full demo of the behavior:

CleanShot.2022-12-06.at.10.06.55.mp4

Footnotes

  1. ctrl + space for me, and also for most keyboard shortcut configurations.

Christ, this is going to be hard to fix. The way to get the default export to be the SDK is to have the index.d.ts file be export = createSDK but that doesn't work because we export types there.

Screen Shot 2022-12-06 at 1 09 45 PM

Maybe if we're exporting JS code we don't export types from the main entrypoint?

Screen Shot 2022-12-06 at 1 11 11 PM

Those types are exported for the user’s convenience, right? Nothing else? If so then yeah I can’t imagine anyone using those in JS projects

yeah if you're using JS you can't use them anyways i guess