I'm trying to build a private module that I know will only be used by another TypeScript project.
According to this (https://github.com/Microsoft/TypeScript/issues/5225) I should be able to simply import my other project without needing to build type definitions.
The problem is I'm missing the type definitions for any dependencies on that library when I try to import it.
Here's the situation:
Lets say you have two projects. lib and app. app imports lib, a pure TypeScript node module.
├── app/
│ ├── dist/
│ │ ├── index.d.ts
│ │ ├── index.js
│ │ └── index.js.map
│ ├── src/
│ │ └── index.ts
│ ├── package.json
│ ├── package-lock.json
│ └── tsconfig.json
└── lib/
├── src/
│ └── index.ts
├── package.json
├── package-lock.json
└── tsconfig.json
app simply imports a function from lib and runs it:
import lib from "lib";
lib("test");
Lib imports a dependency and its types, and exports a function:
package.json:
"dependencies": {
"dotenv": "^6.1.0"
},
"devDependencies": {
"@types/dotenv": "^4.0.3",
"typescript": "^3.1.6"
}
app/src/index.ts:
import dotenv from "dotenv";
dotenv.load()
export default (message: string) => {
console.log(message);
}
When I try to build app I get an error about the missing type definitions from the the lib dependency:
node_modules/lib/src/index.ts:1:20 - error TS7016: Could not find a declaration file for module 'dotenv'. 'lib/node_modules/dotenv/lib/main.js' implicitly has an 'any' type. Try `npm install @types/dotenv` if it exists or add a new declaration (.d.ts) file containing `declare module 'dotenv';` 1 import dotenv from "dotenv";
What's the proper way to handle this scenario? It'll work fine in a mixed JS / TS module, because the "compile boundary" will end at the imported module and its exposed types, but since this module is "pure" TypeScript, it'll crawl all of its dependencies as if it were one large repo.
What's the proper way to set this up? Or is the real issue that npm install doesn't install the dev dependencies? Should I install all of the @types as prod dependencies?