youtube-node icon indicating copy to clipboard operation
youtube-node copied to clipboard

Fix some unintentionally broken typings for callbacks

Open ahlec opened this issue 4 years ago • 0 comments

For the TypeScript definitions for this library, the function signature for the API calls that take a callback argument seem to have been accidentally formatted incorrectly. That is, looking at search, the signature should be:

function search(
  id: string,
  maxResults: number,
  params: Object,
  callback: (error?: Error, data?: YtResult) => void
);

However, the way it's currently written, it's interpreted as:

function search(
  id: string,
  maxResults: number,
  params: Object,
  callback: (error?: Error) => void,
  data?: YtResult
);

It looked like in addition to search, the same issue is also found on getPlaylistItemsById and related. In order to prevent this typo from happening again, I moved the whole function signature to its own type declaration so it's much simpler to use as a function argument.

Additionally, the search function provides an overloaded signature that's used in the example documents, where params is skipped and callback becomes the third parameter. I've added this overloaded signature.

ahlec avatar Mar 15 '20 09:03 ahlec