WebStorm is not detecting type definitions in npm package

I have written an npm module with TypeScript, with the hopes that it can be consumed in node projects with enhanced code assistance. The package.json has a "typings" property pointing to a published `.d.ts` file. However, when I require the module in a node project, I receive no type hints.

Does WebStorm import referenced .d.ts files when doing a require in JavaScript code? 

10 comments
Comment actions Permalink

Webstorm does use "typings" when resolving types in JS code.

Can you provide a sample project that shows up the issue?

0
Comment actions Permalink

Please share a sample project the issue can be recreated with

0
Comment actions Permalink

It's partially working for me. The auto-completion doesn't filter out what is exposed in the index.d.ts.

In short the completion works but it's useless because it's lost in the list of other suggestions.

 

@Elena It should either restrict to what's defined in the index.d.ts (drop the rest) or at least put the suggestions coming from the definition file first in the pop-up list.

I said partially because it doesn't propose me anything for function arguments.

0
Comment actions Permalink

Please see above - I can hardly help unless I have a project to play with

0
Comment actions Permalink

here is a npm project that does not work even with all types provided, works fine on visual studio

https://www.npmjs.com/package/pondsocket

0
Comment actions Permalink

Please could you elaborate on this? does the issue occur when editing the project itself, or you have issue after adding pondsocket (npm install pondsocket) to you app? In both cases, could you share code snippet the issue can be repeated with?

0
Comment actions Permalink

Hey so I have the project installed on another project using npm install as you stated

 

So pond socket is a project I am working on, on the project itself everything works just fine. 

The project has 3 different packages within.

pondsocket/live, pondsocket/client pondsocket/server

When I import an class/function from these sub packages, 

I get the types but only partially

Here is a repo that you can clone and test out https://github.com/Eleven-am/PondLiveTodo you'd notice the typings are not exhaustive and really not helpful

0
Comment actions Permalink

>you'd notice the typings are not exhaustive and really not helpful

what should I try namely to reproduce the issue using this repo?

0
Comment actions Permalink

There's a function called LiveFactory that can be imported from pondsocket/live, this function takes in an object and returns.a class, the object is typed, but not on web storm. it doesn't offer suggestions on what kind of functions the object needs to have and also what the parameters for these functions are. I really suck at explanations but looking at the code, you can tell that it understands what the types are but it displays the wrong and doesn't offer any auto complete I have added some images I hope they help

This photo as you can see it doesn't tell me what the type of any parameters in any function is. This is unusual behaviour for web storm. You should notice the router object. It is an instance of a class. The pageTitle property is actually a getter. Websotrm usually displays getters as functions thus they should be yellow not purple

Hovering over the router you can see that it does indeed know the type of the router, its just incapable of displaying it correctly 

Finally, as you can see here this is the type of the router object, it is indeed typed. Usually clicking on a property should take you to the point on the declaration file where it was created but in my case, I had to click on the imports to actually access this page as clicking on the functions did nothing 

0

Please sign in to leave a comment.