我是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.我该如何解决这个问题呢?
发布于 2020-07-26 05:20:09
@types\package用于那些本身不提供类型的包。如果您打开discord.js package.json file,您将看到这一行"types": "./typings/index.d.ts",。这意味着类型已经包含在主包中,您不需要额外的安装。
因此,首先安装主包,如果TSC会开始抱怨缺少的类型,请搜索类型。此外,有时您可能会发现@types中也缺少该类型。在这种情况下,您必须编写自己的类型。幸运的是,这是一个更少的后箱。
https://stackoverflow.com/questions/63092995
复制相似问题