为什么VS Code不能跟踪JavaScript的变量类型



我正在尝试使用JS创建一个discord bot。我为要实现的每个命令创建一个.js文件,在"main"脚本中有一个检查,它将调用其他命令脚本。当我说VS代码不会告诉我参数的变量类型,也不会告诉我任何关于方法调用的信息时,我将用图片来展示我的意思。Intellisense在这些command.js脚本中似乎也不能很好地工作。

背景信息:我有更多的Java编程经验。无论出于什么原因,JS似乎让我感到困惑,但我想更好地学习和理解它。

我不打算显示所有的代码,只显示示例所需的代码。

main.js脚本:

require('dotenv').config();
const { Client } = require('discord.js');
const client = new Client();
const prefix = "++";
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('.src/commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`.src/commands/${file}`);
client.commands.set(command.name, command);
}
client.on('message', (message) => {
if(message.author.bot) return; 
console.log(`[${message.author.tag}]: ${message.content}`);

if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/); 
const command = args.shift().toLowerCase(); 

if(command === 'ping'){
client.commands.get('ping').execute(message, args);
});

ping.js脚本:

module.exports = {
name: 'ping',
description: 'This is a ping command.',

execute(message, args){
message.channel.send('Pong!');
}
}

图片:它只是说任何,我假设任何变量类型,我认为。。。但这似乎很混乱,很难理解。

main.jshttps://gyazo.com/86f7118513df791743def98bcf052f06

ping.jshttps://gyazo.com/06bb2e47a3fd39d2e4445591d8537131

Discord.jssend()返回Promise<(Message)>Promise<(Array<Message>)>(Discord.js docs for channel.send(((。承诺对于任何API中的顺序任务都很好,但似乎不是您的环境可以识别的数据类型。如果VSCode和IntelliJ(以及许多其他IDE(无法识别方法返回值的数据类型,或者它没有预定义(与JS函数或方法相比,在Java中更常见(,它们会将方法的返回值突出显示为any

最新更新