如何安装自定义打字?
问题描述:
我创建了一个包含代码的自定义类型,我想在几个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文件也有问题。请检阅并让我知道我错过了什么?
在此先感谢。
答
node_modules/@types
文件夹仅适用于由npm安装的定义。对于自定义类型,最好在tsconfig.json
内specify typeRoots
。例如:
{
[...]
"compilerOptions": {
[...]
"typeRoots" : ["../path/to/typings", "./node_modules/@types"],
[...]
}
[...]
}