我创建了一个自定义类型包含我想在几个webstorm node.js项目中共享的代码。问题是我试图找到文档,概述如何在项目中包含输入。我尝试使用npm命令,但它没有将文件夹添加到/ node_modules文件夹下的@typings文件夹中。此外,当我编译我试图添加自定义类型的项目时,我在包含键入的项目和我想要添加键入的项目之间的mongoose库中出现重复错误。我不确定问题是什么。
tsconfig.json(对于新类型):
{
"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(应该安装输入的地方):
{
"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
}
我试图按照文档进行操作。在打字稿网站上但我找不到资源概述如何安装一旦创建。虽然,为了不安装自定义类型,我认为我的tsconfig文件也存在问题。请检讨并告诉我我错过了什么?
提前致谢。
答案 0 :(得分:1)
node_modules/@types
文件夹仅适用于由npm安装的定义。对于自定义类型,最好在tsconfig.json
内specify typeRoots
。例如:
{
[...]
"compilerOptions": {
[...]
"typeRoots" : ["../path/to/typings", "./node_modules/@types"],
[...]
}
[...]
}