Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typeof arguments object in TypeScript

I basically have this:

function foo(){

 // literally pass the arguments object into the pragmatik.parse method
 // the purpose of pragmatik.parse is to handle more complex variadic functions

 const [a,b,c,d,e] = pragmatik.parse(arguments);

 // now we have the correct arguments in the expected location, using array destructuring


}

so we have the pragmatik.parse method:

function parse(args){

   // return parsed arguments

}

now I want to use TypeScript to define types, all I know is that arguments is an Object:

function parse(args: Object){


}

so my question is: does TypeScript give a definition or type for an arguments object in JS? Sorry this is a bit meta, but please bear with me, what I am asking about is sane.

like image 337
Alexander Mills Avatar asked Oct 29 '22 11:10

Alexander Mills


1 Answers

My Webstorm IDE suggests that this might be IArguments, which is provided by: lib/es6/d.ts, which is somewhere out there. Maybe someone can verify this is correct, but I am fairly certain.

So the answer would be:

function parse(args: IArguments){


}

and the full signature would be:

function parse(args: IArguments) : Array<any> {


}

since the parse method returns a generic array

like image 106
Alexander Mills Avatar answered Nov 15 '22 06:11

Alexander Mills