当前位置: 首页 > 知识库问答 >
问题:

如何在VSCode中使用TypeScript使intellisense为我的模块工作

何琨
2023-03-14

我正在用VSCode中的nodejs和electron构建一个应用程序。

我目前使用javascript,但我想切换到tyescript更好的代码验证和智能感知。

Intellisense对于外部模块(electron、lodash、node-core模块)运行良好,但我无法让它与我自己的模块一起工作。

我在包中添加了我的模块(我只在下面的代码中显示其中一个)作为依赖项。json:

"dependencies": {
    ...
    "renderer-rpc": "file:local_modules/renderer-rpc",
    ...
  }

这是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) {
        ...
    }
}

然后在我的主要。ts(位于项目的根部)我做以下工作:

import {mainRpc} from 'renderer-rpc'

mainRpc.

我没有从我的模块得到任何建议。按CTRL键或空格键。

这是我的tConfig。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"
  }
}

共有1个答案

陆浩博
2023-03-14

将以下内容添加到“渲染器rpc”包中的tsconfig中:

"declaration": true,

这将强制typescript编译器在编译期间创建声明(.d.ts)文件。

还有一件事,在“渲染器rpc”中,您应该将其添加到包中。json(修改路径以指向主打字文件):

 "typings": "./dist/index.d.ts"
 类似资料:
  • 我有以下项目结构: 以及以下 假设我在中安装了(甚至安装了)。当我尝试导入时,例如或,这两个导入都是错误的,并显示消息“Cannot find module…”等。 在编写导入字符串时,VSCode建议我使用中的模块,但不建议使用的文件夹。 相对导入仍然有效,但这是地狱,你知道。 我绝对是TypeScript的新手,但我正在根据“模块解析”TypeScript文档做事,它不起作用。 非常感谢这里的

  • Laravel Extra Intellisense This extension provides Laravel routes, views and ... autocomplete for VSCode. Autocomplete Route names and route parameters Views and variables Configs Translations and tra

  • 问题内容: Deno超级酷。我早上看过它,现在想迁移到deno。我试图将现有的nodejs脚本移至deno。谁能帮助我使用deno中的npm模块。我需要esprima模块。这个有包https://github.com/denoland/deno_third_party/tree/master/node_modules,但是我不知道怎么使用。 问题答案: Deno提供了一个节点兼容性库,该库将允许使

  • 我们为什么使用: 而不是: ?

  • -或者- 或者我应该以目前相同的模块方式设置它们?我正在尝试,但它总是给我错误,不知道如何在没有类的模块中!

  • 我发现我不能仅仅在JDK框架中运行语句。 编辑1:我被要求说得更清楚一些: (使用VSCode) 我如何将OpenCSV添加到我的框架中? 至 如何在JDK中实现OpenCSV-CSVReader