javascript 有没有办法让Intellisense在子目录中工作?

2ic8powd  于 2023-06-20  发布在  Java
关注(0)|答案(1)|浏览(118)

我一直在重新访问我用Discord.JS做的一个机器人,我一直在努力解决的问题是,每当在子目录(例如,myproject/commands/moderation)或index.js之外的任何文件,我没有得到discord.js的Intellisense建议,而是必须手动输入所有内容。
有什么方法可以让Intellisense在子目录中给予我建议吗?或者,更有可能的是,我做错了什么吗?

pod7payv

pod7payv1#

要么切换到TypeScript并键入注解值,要么在定义函数时使用JSDocs。如果你已经在使用TypeScript,那么你需要声明要使用的数据的形状。
TypeScript:

  1. import { SlashCommandBuilder } from "discord.js";
  2. import type { CommandInteraction } from "discord.js";
  3. interface Command {
  4. data: SlashCommandBuilder,
  5. execute: (interaction:CommandInteraction) => void;
  6. };
  7. module.exports = {
  8. data: ...,
  9. execute(interaction) {
  10. }
  11. } satisfies Command;

JSDocs:

  1. // Command file
  2. import { CommandInteraction } from 'discord.js'; // If using ESM
  3. const { CommandInteraction } = require('discord.js'); // If using CommonJS
  4. module.exports = {
  5. data: ...,
  6. /**
  7. *
  8. * @param {CommandInteraction} interaction
  9. */
  10. execute(interaction) {
  11. }
  12. };

JSDocs GuideTypeScript Guide

展开查看全部

相关问题