Skip to content

Commit

Permalink
Fix the return type of walkInvocationTree's callback to allow void …
Browse files Browse the repository at this point in the history
…returns as intended (#765)

* Allow void returns on the walker as intended
* Add changelog entry
  • Loading branch information
Shaptic authored Sep 12, 2024
1 parent cd90e7b commit 83c4960
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Fixed
* Fix the TypeScript definition of `walkInvocationTree` to allow void returns on the callback function as intended rather than forcing a `return null` ([#765](https://github.com/stellar/js-stellar-base/pull/765)).


## [`v12.1.0`](https://github.com/stellar/js-stellar-base/compare/v12.0.1...v12.1.0)

Expand Down
3 changes: 2 additions & 1 deletion src/invocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ export function buildInvocationTree(root) {
* @param {xdr.SorobanAuthorizedInvocation} [parent] this `node`s parent node,
* if any (i.e. this doesn't exist at the root)
*
* @returns {boolean?} returning `false` is a hint to stop exploring
* @returns {boolean|null|void} returning exactly `false` is a hint to stop
* exploring, other values are ignored
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ export type InvocationWalker = (
node: xdr.SorobanAuthorizedInvocation,
depth: number,
parent?: any
) => boolean|null;
) => boolean|null|void;

export function walkInvocationTree(
root: xdr.SorobanAuthorizedInvocation,
Expand Down
6 changes: 6 additions & 0 deletions types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,9 @@ new StellarSdk.ScInt(BigInt(1234)); // $ExpectType ScInt
(['i64', 'u64', 'i128', 'u128', 'i256', 'u256'] as StellarSdk.ScIntType[]).forEach((type) => {
new StellarSdk.ScInt(1234, { type }); // $ExpectType ScInt
});

const root = new StellarSdk.xdr.SorobanAuthorizedInvocation({
function: new StellarSdk.xdr.SorobanAuthorizedFunction(),
subInvocations: [],
});
StellarSdk.walkInvocationTree(root, (_node, _depth, _parent) => {});

0 comments on commit 83c4960

Please sign in to comment.