Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript: Parameters with rest readonly array give never [duplicate]

Tags:

typescript

I am seeing a weird (maybe 🤷‍♂️) behavior of Parameters utility type. Given code:

const testFn = (...args: readonly number[]) => args;
type l = typeof testFn;
type e = Parameters<l>;

It doesn't change if I use ReadonlyArray<number> instead, though that is to be expected since they are synonyms.

Why does TypeScript say that type of e is never? This was tested on TypeScript v4.3.5. Link to the playground.

like image 553
Kapelianovych Avatar asked Nov 15 '22 01:11

Kapelianovych


1 Answers

This is a known issue: Inference from rest parameters has strange inconsistent results #37193.

like image 185
Inigo Avatar answered Feb 16 '23 00:02

Inigo