【问题标题】:How do I get VSCode to recognize current package Javascript imports?如何让 VSCode 识别当前包 Javascript 导入?
【发布时间】:2018-07-20 10:42:17
【问题描述】:

VSCode intellisense 很棒,当我导入类似的 javascript 函数时

import func from './file';

vs code 会给我一个有用的对话框,其中包含来自 jsdoc 的参数。这是因为我使用的是相对文件路径。

但是,如果我正在使用我当前的包,让我们将其称为我的 package.json 中列出的“公共”,并尝试使用其绝对路径引用文件,intellisense 不会提取该文件.

// import the same file as above, but using absolute path
// public is the name of the current npm package
import func from 'public/subfolder/file'; 

智能感知不再出现。

这是错误还是配置问题?

【问题讨论】:

    标签: javascript visual-studio-code javascript-intellisense


    【解决方案1】:

    第一步

    创建一个jsconfig.json 文件来指示vs code 中的JavaScript 项目,只需转到vs code 底部并单击绿色灯泡图标即可。

    它会要求你创建jsconfig.json。创建jsconfig.json 文件,该文件将包含以下代码。

    //jsconfig.json
    {
     // See https://go.microsoft.com/fwlink/?LinkId=759670
     // for the documentation about the jsconfig.json format
     "compilerOptions": {
     "target": "es6",
     "module": "commonjs",
     "allowSyntheticDefaultImports": true
     },
     "exclude": [
     "node_modules",
     "bower_components",
     "jspm_packages",
     "tmp",
     "temp"
     ]
    }
    

    第二步 全局安装类型,以便为 express、mongoose、angular 等节点模块下载 TypeScript 定义文件(类型)。

    npm install typings --global

    TypeScript 定义文件是用 TypeScript 编写的,为函数及其参数提供 VS IntelliSense 体验。让我们为 express 安装类型,如下所示:

    typings insall dt~express --global

    让我们尝试一下 express 的编码体验。您将看到用于 express 的出色智能感知。

    【讨论】:

      猜你喜欢
      • 2021-09-11
      • 2019-10-27
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 2021-10-30
      相关资源
      最近更新 更多