【问题标题】:A rest element must be last in a tuple type元组类型中的剩余元素必须位于最后
【发布时间】:2021-03-12 03:37:35
【问题描述】:

为cb写类型时:

const fn1 = (
  cb: (...args: [...args: any[], fn2: () => string, fn3: () => string]) => any,
  ...args: any[]
) => {
  const fn2 = () => 'fn2'
  const fn3 = () => 'fn3'
  cb(...args, fn2, fn3)
}

运行tsc,报错:

A rest element must be last in a tuple type.

【问题讨论】:

标签: typescript types type-definition


【解决方案1】:

原来我一直在使用全局tsc,也就是v3.2.9,难怪我的行为与其他人不同。当我切换到本地的tsc即v4.2.3时,代码编译成功。

【讨论】:

  • 当我运行 tsc -v 我得到 Version 4.2.3 但是当 tsc 它运行良好当我运行 npm run build 执行 tsc; cp package.json ./lib/src/package.json 我得到 A rest element must be last in a tuple type. Npm 更新修复了一切。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-16
  • 2023-03-04
  • 2015-10-19
相关资源
最近更新 更多