【发布时间】:2022-01-06 11:36:54
【问题描述】:
当我在类型声明文件中遇到问题时,我正在使用 TypeScript 编写一个小型 Discord 机器人。
index.d.ts:
declare module 'configuration' {
/**
* Configuration of your bot.
*/
export type IConfiguration = {
/**
* Token of your bot.
*/
token: string
/**
* Prefix of your bot.
*/
prefix: string
/**
* Time to cool down the bot commands.
*/
coolDown: number
}
/**
* Context at which we are logging.
*/
export type IContext = '[Bot]' | '[Client]' | '[Server]'
/**
* Type for the commands
*/
export type ICommand = (message: Message, arguments: string[]) => void | any
}
显然 index.ts 无法加载声明文件?
执行import { IConfiguration, ICommand } from 'configuration'; 只会返回错误:
Cannot find module 'configuration' or its corresponding type declarations.ts(2307)
我一直在网上寻找,提到的一些解决方案在 package.json 和 tsconfig.json 中列出了您的类型,但似乎都没有帮助。
TSConfig.json:
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"target": "es2015",
"module": "commonjs",
"resolveJsonModule": true,
// TBD it is desired to enabled strict type checking at some point:
"strict": false,
"typeRoots": ["./types", "./node_modules/@types"]
}
}
我不知道为什么这不起作用。非常感谢。
【问题讨论】:
标签: typescript ecmascript-6 types discord.js type-declaration