Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

new(...args) => T syntax

Tags:

typescript

I've come across the following type annotation on a function parameter:

typeFilter : new(...args) => T

where T is a generic parameter on the function.

What does new(...args) mean in this context, and where is it documented?

like image 339
Zev Spitz Avatar asked Mar 06 '23 22:03

Zev Spitz


1 Answers

TL;DR new(...args) => T represents constructor of T taking any parameters.

new describes "static" part of a class/function, meaning it is a constructor and consumer can create new instance of T using new keyword. Example here.

As for ...args - these are rest parameters

Rest parameters are treated as a boundless number of optional parameters. When passing arguments for a rest parameter, you can use as many as you want; you can even pass none

like image 82
Aleksey L. Avatar answered Mar 14 '23 20:03

Aleksey L.