如何获得VSCode来识别当前的程序包Javascript导入? [英] How do I get VSCode to recognize current package Javascript imports?

查看:176
本文介绍了如何获得VSCode来识别当前的程序包Javascript导入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我导入javascript函数之类的

VSCode intellisense is great, when I import a javascript function like

import func from './file';

vs代码将为我提供一个有用的对话框,其中包含来自jsdoc的参数.这是因为我使用的是相对文件路径.

vs code will give me a helpful dialog with its arguments from jsdoc. This is because I'm using a relative file path.

但是,如果我正在使用当前的程序包,则将其称为package.json中列出的"public",并尝试使用其绝对路径引用文件,则intellisense不会从文件中获取信息

However, if I'm working with my current package, lets call it "public" as listed in my package.json, and try to reference a file using its absolute path, the intellisense doesn't pick up on the file.

// 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'; 

intellisense不再出现.

intellisense no longer appears.

这是错误还是配置问题?

Is this a bug or a configuration issue?

推荐答案

Step1

创建一个jsconfig.json文件以指示vs代码中的JavaScript项目,只需转到vs代码的底部,然后单击绿色灯泡图标即可.

Create a jsconfig.json file to indicate a JavaScript project within vs code, just go to the bottom of vs code and click on green bulb icon.

它将要求您创建jsconfig.json.创建jsconfig.json文件,其中将包含以下代码.

It will ask you to create jsconfig.json. Create jsconfig.json file which will contain the following code.

//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"
 ]
}

Step2 全局安装类型,以下载Express,Mongoose,Angular等节点模块的TypeScript定义文件(类型).

Step2 Install typings globally for downloading TypeScript Definition files (typings) for node modules like express, mongoose, angular etc.

npm install typings --global

TypeScript定义文件使用TypeScript编写,以提供VS IntelliSense的功能及其参数体验.让我们安装Express的类型,如下所示:

TypeScript definition files are written in TypeScript to provide a VS IntelliSense experience for the functions and it's parameters. Let's install typings for express as given below:

typings insall dt~express --global

让我们尝试快递的编码经验.您将看到出色的智能表达.

Let's try the coding experience for express. You will see the great intelliSense for express.

这篇关于如何获得VSCode来识别当前的程序包Javascript导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆