突出显示未使用的变量,并且导入无法正常工作 [英] Highlight unused variables and imports is not working properly

查看:62
本文介绍了突出显示未使用的变量,并且导入无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VSCode 2018年5月(1.24版,MacOs)

VSCode May 2018 (version 1.24, MacOs)

功能:突出显示未使用的变量和导入

未使用的变量,参数和导入现在在JavaScript和TypeScript中显示为灰色.

Unused variables, parameters, and imports are now greyed out in JavaScript and TypeScript.

我创建了一个简单的test.js文件:

I created a simple test.js file:

var var1  // not used => should be greyed out
var var2 = 2
var var3

var3 = var2 + 2
console.log(var3)

该变量在我的屏幕上未显示为灰色. 我正在使用主题Dark+.

The variable is not greyed out on my screen. I am using the theme Dark+.

可能是什么问题?

推荐答案

此功能仅在包含至少一个requireimportexport语句的文件中起作用.

This feature only works in a file that contains at least one require, import, or export statement.

如果我创建像您一样的test.js文件,则会遇到相同的问题.但是,将以下任何行放在文件顶部即可解决问题:

If I create a test.js file like yours, I experience the same issue. However, placing any of these lines at the top of the file fixes it:

require('');

import { } from "";

module.exports.mymodule = {};

这显然是显然是设计原因,而不是错误.

这篇关于突出显示未使用的变量,并且导入无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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