typescript - 在哪里可以找到 tsc 错误列表?
问题描述
我正在尝试使用 tsc 为一些现有的 javascript 代码自动生成打字稿声明文件。打字稿编译器给了我一些我不理解的错误(在这种情况下为 TS9005)。是否有 tsc 生成的所有错误代码的参考列表以及它们在某处的含义的解释?会比较方便。
解决方案
诊断消息列表可以src/compiler/diagnosticMessages.json
在 TypeScript 存储库中找到。该文件的结构如下:
{
"Unterminated string literal.": {
"category": "Error",
"code": 1002
},
"Identifier expected.": {
"category": "Error",
"code": 1003
},
"'{0}' expected.": {
"category": "Error",
"code": 1005
},
"A file cannot have a reference to itself.": {
"category": "Error",
"code": 1006
},
// etc...
}
但是,没有我知道的带有解释的列表。
TS9005 ( Declaration emit for this file requires using private name '{0}'. An explicit type annotation may unblock declaration emit.
) 表示 JS 文件正在导出具有未导出类型的内容。例如:
foo.d.ts
interface Foo {
foo: number
}
declare function foo(): Foo
export = foo
bar.js
// @ts-check
module.exports = require('./foo')()
TypeScript 无法为其创建声明文件,bar.js
因为导出的类型为Foo
,而不是从 导出foo.d.ts
。您可以通过为导出添加类型声明来解决此问题:
bar.js
// @ts-check
/** @type {{foo: number}} */
module.exports = require('./foo')()
推荐阅读
- python - 我如何强加一个必须由集合的*任何两个*成员满足的条件?
- node.js - EJS:ReferenceError:未定义机器人
- excel - 我不断收到“您为此函数输入了太多参数”为什么
- c# - 将 .NET Core 2.1 迁移到 .NET Core 3.0
- swift - 如何检查
在 Swift 5 中并避免“NSInvalidArgumentException”? - azure - 将 Blob 存储密钥更新到应用程序
- docker - 无法在 Oracle Linux 上启动 Docker
- html - 如何在引导程序中以自定义宽度在页面上的 1 行中显示 5 个输入
- arrays - as3 2d 数组,随机数不会在行或列中产生 3 个
- amazon-web-services - AWS DocumentDB 将流数据可用性从默认更改为 24 小时