vscode自动类型获取,开玩笑 [英] vscode automatic type acquisition for jest

查看:103
本文介绍了vscode自动类型获取,开玩笑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有vscode 1.9,我想在智能测试中使用intellisense.问题在于describeitexpect等在玩笑中是全局可用的,您不需要在测试文件中将它们import都可用.因此,vscode将不会显示出对它们的智能感知.

I have vscode 1.9 and I want to have intellisense for jest tests. The problem is that describe, it, expect etc are globally available in jest and you don't need to import them in your test files. So vscode will not show intellisense for them.

是否存在用于自动类型获取的全局变量配置?

Is there any configuration for globals for automatic type acquisition?

推荐答案

在这种情况下,您有几个选择:

You have a few options in this case:

jest添加到您的package.json:

"dependencies": {
  "jest": "^18.1.0"
}

这仅在使用JavaScript并且没有tsconfig.json的情况下有效.

This only works if you are working JavaScript and do not have a tsconfig.json.

安装@types/jest

$ npm install -D @types/jest

这同时适用于JavaScript和TypeScript项目.但是@types,但可能会被jsconfig.json/tsconfig.json禁用: http://www.typescriptlang.org/docs/handbook/tsconfig-json.html

This should work for both JavaScript and TypeScript projects. However @types but may be disabled by a jsconfig.json/tsconfig.json: http://www.typescriptlang.org/docs/handbook/tsconfig-json.html

在工作区的根目录中创建一个jsconfig.json文件,以专门包含jest:

Create a jsconfig.json file in the root of your workspace to specifically include jest:

{
    "typeAcquisition": {
        "include": [
            "jest"
        ]
    }
}

这仅在启用自动键入获取功能时才适用于JavaScript项目.

This will only work for JavaScript projects when automatic typings acquisition is enabled.

所有这些都应使VSCode能够在不使用importrequire

All of these should allow VSCode to pick up jest's typings without an import or require

这篇关于vscode自动类型获取,开玩笑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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