box / box-node-sdk

A Javascript interface for interacting with the Box API. You can find the node package at
https://www.npmjs.com/package/box-node-sdk
Apache License 2.0
187 stars 121 forks source link

TypeScript: mark callback as optional #857

Closed BaliBalo closed 10 months ago

BaliBalo commented 11 months ago

The current implementation of asynchronous token functions (getTokensAuthorizationCodeGrant, getTokensRefreshGrant, getEnterpriseAppAuthTokens, getAppUserTokens, revokeTokens) can handle both callbacks and promises.

However, in the TypeScript definition, the callback function is not marked as optional, meaning these functions have to be called with an empty function:

// this errors:
const tokenInfo = await getTokensRefreshGrant(refreshToken, null);
// this is fine:
const tokenInfo2 = await getTokensRefreshGrant(refreshToken, null, () => {});

This looks confusing, and is also inefficient as it creates a function in memory for no reason. Could we make them optional? Happy to open a PR if that helps.

Additionally, it could also be nice for these same functions to make options optional as well, instead of having to specify null

mhagmajer commented 11 months ago

Hello @BaliBalo! You've raised valid points. Thank you for the detailed description. I created a PR with the fix.