Scenario
We have a paging API that returns Customer
instances.
We want API users to be able to specify paging options without worrying about the order of the Javascript arguments passed in.
Design
export function fetchCustomers(id:string, options?:PagingOptions):Customer[]
And the PagingOptions
interface looks like this:
interface PagingOptions {
limit?:number
after?:string
}
We can now just check the PagingOptions
argument for the optional parameters:
if (options.limit) { //limit the return result }