alpaca-trade-api-js icon indicating copy to clipboard operation
alpaca-trade-api-js copied to clipboard

[Typescript] Allow for getOrders flexibility without throwing an error

Open davidstackio opened this issue 3 years ago • 1 comments

Thinking the types for getAll() needs updated to allow for not including ALL the parameters. They should all be optional. I believe the file is order.d.ts.

I'm expecting to write code like this: openOrders = await alpaca.getOrders({ status: "open", limit: "500" });

Without getting this error:

error TS2345: Argument of type '{ status: string; limit: string; }' is not assignable to parameter of type '{ status: any; until: any; after: any; limit: any; direction: any; nested: any; }'.
  Type '{ status: string; limit: string; }' is missing the following properties from type '{ status: any; until: any; after: any; limit: any; direction: any; nested: any; }': until, after, direction, nested

I think all it needs is some question marks after the optional parameters: https://www.typescriptlang.org/docs/handbook/2/functions.html#optional-parameters

davidstackio avatar Jan 06 '22 21:01 davidstackio

Yep, just tried it by adding question marks to all the parameters and it worked! image

davidstackio avatar Jan 06 '22 21:01 davidstackio