Аргумент деструктуры: TS2339 Свойство не существует - PullRequest
0 голосов
/ 29 марта 2020

Я работаю с существующей функцией javascript. Я начал использовать опцию --check Js, когда машинный код проверял код, даже если он находится в файле. 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 }
                                                                    ^^^^^^^^^^

ts c, кажется, как-то заключил, что onFold - это функция, и это хорошо, но почему-то жалуется на отсутствие onOverflow. Может кто-нибудь объяснить, почему я получаю это сообщение?

Typescript версии 3.7.5

PS: я обновил пакет машинописных сообщений до последней версии 3.8.3, тот же результат .

1 Ответ

0 голосов
/ 29 марта 2020

Я нашел проблему, это была ошибка в комментариях JSDo c!

Вот оригинал с тонкой ошибкой:

/**
 * Tries to keep input at up to `lineWidth` characters, splitting only on spaces
 * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are
 * terminated with `\n` and started with `indent`.
 *
 * @param {string} text
 * @param {string} indent
 * @param {string} [mode='flow'] `'block'` prevents more-indented lines
 *   from being folded; `'quoted'` allows for `\` escapes, including escaped
 *   newlines
 * @param {Object} options
 * @param {number} [options.indentAtStart] Accounts for leading contents on
 *   the first line, defaulting to `indent.length`
 * @param {number} [options.lineWidth=80]
 * @param {number} [options.minContentWidth=20] Allow highly indented lines to
 *   stretch the line width
 * @param {function} options.onFold Called once if the text is folded
 * @param {function} options.onFold Called once if any line of text exceeds
 *   lineWidth characters
 */
export function foldFlowLines(
  text,
  indent,
  mode,
  { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow }
) { 
//... 
}

Окончательный @param необходимо изменить с options.onFold на options.onOverflow.

...