Reputation: 960
I'm building an application using nodejs and electron in VSCode.
I use javascript currently but I'd like to switch to typescript for better code validation and intellisense.
Intellisense is working fine for external modules (electron, lodash, node core modules) but I can't make it work with my own modules.
I have added my modules (I just show one of them in the following code) as dependencies in my package.json:
"dependencies": {
...
"renderer-rpc": "file:local_modules/renderer-rpc",
...
}
This is the content of renderer-rpc.ts (just the relevant code):
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) {
...
}
}
Then in my main.ts (located in the root of the project) I do the following:
import {mainRpc} from 'renderer-rpc'
mainRpc.
and I don't get any suggestion from my module. Neither pressing CTRL+SPACE.
This is my tsconfig.json
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"sourceMap": true,
"watch": true
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}
And this is my 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"
}
}
Upvotes: 2
Views: 3081
Reputation: 1317
Add the following to your tsconfig in the "renderer-rpc" package:
"declaration": true,
This will enforce the typescript compiler to create declaration (.d.ts) files as well during compilation.
One more thing, in "renderer-rpc", you should add this into your package.json (modify the path to point to your main typings file):
"typings": "./dist/index.d.ts"
Upvotes: 2