如何使用Typescript + Node.js在单独的项目中创建后安装自定义类型?

时间:2017-09-03 17:54:49

标签: node.js typescript npm-install typescript-typings

我正在研究node.js的应用程序,它分布在四个独立的webstorm gui项目中。理想情况下,我想创建一个模块插件库,其中包含一组需要由其他项目共享的代码,即GenericRepository等。我按照typescript网站上列出的文档实现了一个模块插件;模块plugin.d.ts(https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-plugin-d-ts.html)。我运行tsconfig文件编译到dist文件夹,编译成功完成。到现在为止还挺好。

例如,当我尝试使用“npm install --save @types /../ GenericRepository”进行安装时,我收到一条错误消息,指出该文件夹不包含package.json文件。这没有任何意义,因为文件夹中有一个package.json文件。我不确定我做错了什么。

这是GenericRepository文件夹的package.json文件:

{
  "name": "GenericRepository",
  "version": "1.0.0",
  "main": "./dist/index.js",
  "typings": "./dist/index.d.ts",
  "license": "ISC",
  "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"
  }
}

以下是GenericRepository项目的tsconfig.json文件:

{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "ES5",
    "module": "commonjs",
    "moduleResolution": "node",
    "lib": ["ES6"],
    "sourceMap": true,
    "pretty": true,
    "outDir": "dist/",
    "noLib": false
  },
  "filesGlob": [
    "**/*.ts",
    "!node_modules/**/*"
  ],
  "files": [
    "index.ts"
  ],
  "exclude": [
    "node_modules",
    "node_modules/@types",
    "typings.json"
    //"typings/global",
    //"typings/global.d.ts"
  ],
  "compileOnSave": true
}

0 个答案:

没有答案