I created a custom typing contains code that I would like to share across several webstorm node.js projects. The issue is that I am trying to find documentation outlining how to include the typing in a project. I tried to using the npm command but it did not add the folder to the @typings folder under /node_modules folder. Also, when I compile the project that I am trying to add the custom typing to, I am getting duplicate errors for the mongoose library between the project that contains the typing and the project I would like to add the typing to. I am not sure of what the problem could be.
tsconfig.json(for the new type):
{
"name": "newcustomtype",
"description": "...",
"version": "1.0.0",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"scripts": {
"grunt": "grunt"
},
"dependencies": {
"@types/express": "^4.0.35",
"@types/express-jwt": "0.0.34",
"debug": "^2.2.0",
"dotenv": "^4.0.0",
"mongoose": "^4.9.2",
"tslint": "^4.5.1"
},
"devDependencies": {
"@types/mongodb": "^2.1.41",
"@types/mongoose": "^4.7.9",
"@types/node": "^7.0.10",
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-ts": "^6.0.0-beta.15",
"grunt-tslint": "^4.0.1",
"nodemon": "^1.11.0",
"ts-node": "^3.0.2",
"tslint": "^4.5.1",
"typescript": "^2.2.1"
}
}
tsconfig.json(where the typing should be installed):
{
"compilerOptions": {
"module": "commonjs",
"target": "ES5",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"types": ["reflect-metadata"],
"lib": ["ES6"],
"sourceMap": true,
"inlineSources": true,
"pretty": true,
"outDir": "dist",
"rootDir": "src",
"noLib": false
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false
}
I tried to follow the doc. on the typescript website but I have not been able to find a resource outlining how to install once created. Although, for it to not install the custom typing, I think there is also a problem with my tsconfig files as well. Please review and let me know what I am missing?
Thanks in advance.
The node_modules/@types
folder is only for definitions which get installed by npm. For custom typings it would be best to specify typeRoots
within your tsconfig.json
. For example:
{
[...]
"compilerOptions": {
[...]
"typeRoots" : ["../path/to/typings", "./node_modules/@types"],
[...]
}
[...]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.