我在VSCode中使用nodejs和electron构建应用程序。
我目前使用的是javascript,但我想切换到打字稿以获得更好的代码验证和智能感知。
Intellisense适用于外部模块(电子,lodash,节点核心模块),但我无法使用自己的模块。
我已将我的模块(我只是在下面的代码中显示其中一个)添加为package.json中的依赖项:
"dependencies": {
...
"renderer-rpc": "file:local_modules/renderer-rpc",
...
}
这是renderer-rpc.ts(只是相关代码)的内容:
import {ipcMain} from 'electron'
import {ipcRenderer} from 'electron'
export const mainRpc = {
init : function () {
...
}
}
export const rendererRpc = {
init : function (options) {
...
},
call : function (recipient, method, ...args) {
...
},
makeRemote: function (object, recipient) {
...
}
}
然后在我的main.ts(位于项目的根目录中)中,我执行以下操作:
import {mainRpc} from 'renderer-rpc'
mainRpc.
我从模块中得不到任何建议。既不按CTRL + SPACE。
这是我的tsconfig.json
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"sourceMap": true,
"watch": true
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}
这是我的package.json:
{
"name": "image-gallery",
"version": "1.0.0",
"private": true,
"main": "main.js",
"scripts": {
"test": "mocha",
"start": "electron ."
},
"author": "Mic",
"license": "ISC",
"dependencies": {
"@types/node": "^8.5.1",
"DAL": "file:local_modules/DAL",
"async-parallel": "^1.2.3",
"bootstrap": "^3.3.7",
"db-layer": "file:local_modules/db-layer",
"electron-pug": "^1.5.1",
"jimp": "^0.2.28",
"jquery": "^3.2.1",
"lodash": "^4.17.4",
"nedb": "^1.8.0",
"pug": "^2.0.0-rc.4",
"q": "^1.5.1",
"renderer-rpc": "file:local_modules/renderer-rpc",
"scattered-store": "^1.0.0"
},
"devDependencies": {
"electron": "1.7.9",
"mocha": "^4.1.0",
"mock-require": "^2.0.2",
"typescript": "^2.6.2"
}
}
答案 0 :(得分:0)
在" renderer-rpc"中将以下内容添加到tsconfig中包:
"declaration": true,
这将强制typescript编译器在编译期间创建声明(.d.ts)文件。
还有一件事,在" renderer-rpc"中,你应该将它添加到你的package.json中(修改指向你的主要打包文件的路径):
"typings": "./dist/index.d.ts"