简体   繁体   中英

Autocompletion for private NPM package

I am trying to create my own private NPM package. I want to use this package in several other projects of mine. You can imagine it like API library. I use babel for code transpilation.

Let's assume very simple example:

src/index.js

class API {
  static testMethod() {
    return null
  }
}

export default API

This file gets transpiled using babel: babel./src --out-dir./dist --source-maps

When I publish this package and install it in another project everything works just fine but IDE shows me warning that API class doesn't have method testMethod . I am using WebStorm. I also tried VS Code and it doesn't work either.

My questions are:

  • What am I missing?

  • Do I need to write JSdoc comments or use Typescript?

  • Aren't source maps enough?

WebStorm version 2019.2.4

Error: 在此处输入图像描述

Source maps aren't enough. You need *.d.ts definition files to enable autocomplete. I strongly advise you to use typescript. You can find a very brief tutorial here https://cameronnokes.com/blog/the-30-second-guide-to-publishing-a-typescript-package-to-npm/ on how to publish a typescript package with autocomplete

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM