0
votes

I have two NPM modules, let's call them A and B.

Both written in TypeScript. Both compiles into CommonJS Node-like modules.

Module B depends on module A, so I install in with npm install --save A. It have been properly installed into node_modules/A folder.

Then in my new module B I want to use class Class from module A. So I write:

// import Class from 'A/lib/Class'; <- This import statement must be suggested by PhpStorm

export default class NewClass extends Class {
    // boring implementation details
}

The problem is PhpStorm (version 2016.3.2) does not suggest to add any import statement like it does for local project files. TypeScript Service says that class name not found and PhpStorm only suggests to rename class Class.

Is there any possibility to say PhpStorm to give me suggestions, code completition for modules written in TypeScript and distributed via NPM?

I think the number of TypeScript modules grows over time and it's much easier in TypeScript projects to use TypeScript code directly from modules, without .d.ts files.

1
The import name would probably not be "A/lib/Class". It would be whatever you exported it from. What does the main key of the A package look like? That will point to the main module. It would be something like import Class from "A" or import { Class } from "A", or some other variation, depending on how you exported it. A link to the npm package or its repository would also help so people can investigate it better. - zeh
Module A is a library of classes. For example class Transition placed in file lib/UI/Animation/Transition.ts under A module and exported as default. Inside module B I import it using import Transition from 'A/lib/UI/Animation/Transition';. And PhpStorm does not suggest to import this file automatically, i must write imports myself. - Alex Chandler
@zeh, is there any possibility to say PhpStorm to give me suggestions, code completition for modules written in TypeScript and distributed via NPM? As I understood, PhpStorm does not index node_modules folder by default... - Alex Chandler

1 Answers

0
votes

I've found solution.

If you want to distribute TypeScript modules via NPM and have advantages of IDE intellisense, you need to set compilerOptions.declaration to true in youe tsconfig file. This will say TS compiler to generate d.ts definitions for each .ts file. In dependent modules IDE will properly suggest you to import files is some of types are not resolved in your code.