Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gruntjs Gruntfile.js中的intellisense_Gruntjs_Typescript_Intellisense_Visual Studio Code - Fatal编程技术网

Gruntjs Gruntfile.js中的intellisense

Gruntjs Gruntfile.js中的intellisense,gruntjs,typescript,intellisense,visual-studio-code,Gruntjs,Typescript,Intellisense,Visual Studio Code,有可能让intellisense在Grunfile中工作吗 由于“grunt”不是全局变量,而是GrunFile VSCode中的一个参数,因此将假定它只是一个未知函数参数“any” module.exports = function(grunt) {...} 当我将类型添加到参数中时,intellisense工作正常,但grunt不会,因为它是JS而不是TS module.exports = function(grunt: IGrunt) {...} 您可以创建grunfile.ts并将T

有可能让intellisense在Grunfile中工作吗

由于“grunt”不是全局变量,而是GrunFile VSCode中的一个参数,因此将假定它只是一个未知函数参数“any”

module.exports = function(grunt) {...}
当我将类型添加到参数中时,intellisense工作正常,但grunt不会,因为它是JS而不是TS

module.exports = function(grunt: IGrunt) {...}

您可以创建
grunfile.ts
并将TypeScript与intellisense一起使用。编译后的版本(
gruntfile.js
)将由GruntJs使用。

步骤用于未初始化的

设置打字 为Grunt安装打字功能

npm install --save @types/grunt 
找到打字文件

确保IDE知道此打字文件的位置:

./node_modules/@types/grunt/index.d.ts
使用自动完成 这在.ts或.js中是可能的,无论您喜欢哪个。。。(我使用typescript,因为编译器做了很多类型安全检查)

在Typescript中自动完成

npm install --save @types/grunt 
将现有的gruntfile.js重命名为gruntfile.ts

添加IGrunt类型以启用自动完成:

module.exports = function (grunt: IGrunt) {
    // auto-complete works for grunt-dot now
    ...
}
最后,记住编译gruntfile.ts,以便它生成一个新的gruntfile.js

在Javascript中自动完成

npm install --save @types/grunt 
如果您希望避免使用typescript

用于在javascript中启用自动完成:

/**
* 
* @param {IGrunt} grunt
*/
module.exports = function (grunt) {
    // auto-complete works for grunt-dot now
    ...
}

如果您想坚持使用JavaScript,它将与您的JavaScript运行得一样好,但使用intellisense与使用
grunt:IGrunt时一样好:

/**
*@param{IGrunt}grunt
*/
module.exports=函数(grunt){…}
(为什么是的,已经有人建议这样做了,但我想明确一点,这可能是你需要做的所有事情。)

在Visual Studio代码中,如果将typescript.disableAutomaticTypeAcquisition设置为true(或者该功能遇到了某种障碍)并且在包.json中没有@types/grunt,这将不起作用,但如果出现任何情况,grunt:IGrunt似乎也不起作用