【问题标题】:How to install typings of discord.js for typescript?如何为打字稿安装 discord.js 的类型?
【发布时间】:2020-11-15 11:11:22
【问题描述】:

我是 typescript 的新手,我发现要使用 npm 包,我首先需要为其安装它的类型,例如

npm install --save @types/node-schedule

但是我也在使用 discord.js,但这不起作用

import * as Discord from 'discord.js';

然后

npm install --save @types/discord.js

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fdiscord.js - Not found
npm ERR! 404
npm ERR! 404  '@types/discord.js@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

我该如何解决这个问题?

【问题讨论】:

  • 包名是discord.js,而不是@types/discord.js。只有在使用 javascript 库或其他不包含类型信息的库时才需要输入。

标签: node.js typescript discord.js


【解决方案1】:

@types\package 用于那些自身不提供类型的包。如果你打开 discord.js package.json file,你会发现"types": "./typings/index.d.ts", 这一行。这意味着这些类型已经包含在主包中,您不需要额外安装。

所以,首先安装主包,如果 TSC 开始抱怨缺少类型,请搜索类型。此外,有时,您可能会发现 @types 中也缺少该类型。在这种情况下,您将不得不编写自己的类型。幸运的是,这是一个更少的后壳。

【讨论】:

    猜你喜欢
    • 2019-02-07
    • 1970-01-01
    • 2019-06-15
    • 2017-04-13
    • 2016-06-18
    • 2023-03-23
    • 2022-11-02
    • 2019-06-05
    • 2020-05-28
    相关资源
    最近更新 更多