Reputation: 1525
I have two projects (client and server) that should share the same definitions. To achieve this i outsourced my definition (.d.ts
) in an extra npm package that I linked back to both projects via npm link
. The types in the new npm package are not recognized by the two main projects. I tried package.json
(types
) settings and some settings in tsconfig.json
(types
, typeRoot
) in various combinations, but I didn't get the right one.
What I have to set up in the definition package and the main packages to get that working?
Upvotes: 6
Views: 4091
Reputation: 1525
types
and typeRoots
didn't work for me and I try many different paths/combinations (especially in typeRoots
).
Finally I added the line
"include": [
...,
"node_modules/<my-npm-package>/*.ts"
],
in tsconfig.json and my outsourced typings are available in the projects.
Upvotes: 6
Reputation: 1311
Unfortunately, you don't give enough information to deduct what is going wrong. First of all, if you use index.d.ts
inside node_moudels, and put in the root of your npm package, typescript should automatically use types from the package, no extra setup needed.
However, you use index.d.ts
file only if you type JavaScript code (compiled code). If you just want to share types, you use index.ts
and then include the path to the folder where shared type is inside "typeRoots"
.
Upvotes: 0