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

我正在为四个独立的webstorm gui项目中的node.js应用程序工作。 理想情况下,我想创build一个模块插件库,其中包含一组需要由其他项目共享的代码,即GenericRepository等。我在打字稿网站上列出的文档中实现了一个模块插件; module-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 }