【发布时间】:2020-03-29 06:29:02
【问题描述】:
我正在使用现有的 javascript 函数。我开始使用 --checkJs 选项,使用打字稿检查代码,即使它位于 .js 文件中。该函数对其最后一个参数使用解构,这似乎很重要,而且令人困惑......
export function foldFlowLines(
text, indent, mode,
{ indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow }
) {
// ...body containing...
if (overflow && onOverflow) onOverflow()
if (folds.length === 0) return text
if (onFold) onFold()
// ...
}
我收到以下消息:
src/foldFlowLines.js:42:66 - error TS2339: Property 'onOverflow' does not exist on type
'{ indentAtStart?: number; lineWidth?: number; minContentWidth?: number; onFold: Function; }'.
42 { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow }
^^^^^^^^^^
tsc 似乎以某种方式推断onFold 是一个函数,这很好,但不知何故它抱怨onOverflow 不存在。谁能解释我为什么会收到这条消息?
Typescript 3.7.5 版
PS:我将 typescript 包更新到最新版本 3.8.3,结果相同。
【问题讨论】:
标签: typescript tsc