【发布时间】: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.
【问题讨论】:
-
这对于在 TS4.2 中输入更好的“rest”元组来说是一个很好的用例:devblogs.microsoft.com/typescript/announcing-typescript-4-2/…
-
this 是您要找的吗?如果没有一些示例来说明您希望能够在函数内部和外部做什么,很难说清楚。
标签: typescript types type-definition