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?
Stages: (1) Copy client and server code, install client dependencies and build client. (2) Start afresh, copy server code only, install server dependencies and build server.
You can use npm to install TypeScript globally, this means that you can use the tsc command anywhere in your terminal. To do this, run npm install -g typescript . This will install the latest version (currently 4.8). An alternative is to use npx when you have to run tsc for one-off occasions.
TypeScript is neither a frontend or backend language, but rather a superset of the already established and well-known software language, JavaScript.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With