Bar Goldinfeld Bar Goldinfeld -4 years ago 237
TypeScript Question

WebStorm typings inferring

I'm building a library using TypeScript. I created declaration files and added the 'typings' option to my package.json (I also tried using 'types').
Now my problem is when I try to install the package, WebStorm won't infer the typings (in contrary to the way it works with Angular2 for example).

It seems like I'm missing something with my package.json / typings, so:

index.d.ts:

declare module 'my-library' {
export * from "my-library/index";
}

declare module 'my-library/index' {
export {
LibraryLogic
}
from "my-library/LibraryLogic";
}

declare module 'my-library/LibraryLogic' {
export class LibraryLogic {
constructor(someNumber: number);
}
}


Usage:

import { LibraryLogic } from 'my-library';

let a = new LibraryLogic(3);


Note: Everything compiles just fine, it's just that it would be easier for programmers to use my library if WebStorm would auto-complete them.

Answer Source

works fine for me using WebStorm 2016.3.3.

My setup:

  1. in my project package.json I have added "my-library" as a dependency
  2. in node_modules/my-library/package.json I have: "types": "./index.d.ts"

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download