繁体   English   中英

如何安装自定义类型?

[英]How to install custom typings?

我创建了一个自定义类型包含我想在几个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安装的定义。 对于自定义类型,最好在typeRoots指定 tsconfig.json 例如:

{
  [...]
  "compilerOptions": {
    [...]
    "typeRoots" : ["../path/to/typings", "./node_modules/@types"],
    [...]
  }
  [...]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM