Skip to content

Strongly typed next function.#20

Open
WouterSpaak wants to merge 1 commit intojvdieten:masterfrom
WouterSpaak:strongly-type-next-function
Open

Strongly typed next function.#20
WouterSpaak wants to merge 1 commit intojvdieten:masterfrom
WouterSpaak:strongly-type-next-function

Conversation

@WouterSpaak
Copy link

Hello @jvdieten!

Thank you for this little library, we're using it for end-to-end tests in various places where we generate XML files for geospatial analysis.

In this PR, I changed the type signature of the next argument to be next: (result: IDiffResultModel[]) => void, to ensure that any function passed as the final argument to diff and diffAsXml will get the correct type information.

This shouldn't be a breaking change, and if it is for downstream users, they've probably got a bug anyway...

I was also going to alter the type signature of the functions to return something generic, like:

export function diffAsXml<R>(
  lhs: string,
  rhs: string,
  schema: ISchema | undefined,
  options: IOptionsModel | undefined,
  next: (result: IDiffResultModel[]) => R
): R {
  return next(compareObjects(...));
}

Then you could use it like so:

const result = diffAsXml(lhs, rhs, undefined, undefined, (r) => {
  return 'I am the result of the callback!';
});

console.log(result); // 'I am the result of the callback!'

However I feel that may be too much of an impact to the API. If you feel this would be valuable, I'd be more than happy to create a seperate pull request for that.

Kind regards,
Wouter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant