Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A rest element must be last in a tuple type

When writing type for cb:

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

Run tsc, an error is thrown:

A rest element must be last in a tuple type.
like image 632
Wenfang Du Avatar asked Mar 01 '23 16:03

Wenfang Du


1 Answers

It turns out I was using the global tsc the whole time, which was v3.2.9, no wonder I had behaviors different from other people's. When I switched to the local tsc which was v4.2.3, the code was compiled successfully.

like image 70
Wenfang Du Avatar answered May 16 '23 11:05

Wenfang Du