Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing methods to TypeScript definitions #766

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

### Fixed
* Add missing methods to TypeScript definitions ([#766](https://github.com/stellar/js-stellar-base/pull/766)).
* 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)).


Expand Down
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ export class FeeBumpTransaction extends TransactionI {
);
feeSource: string;
innerTransaction: Transaction;
get operations(): Operation[];
}

export class Transaction<
Expand Down Expand Up @@ -1058,7 +1059,9 @@ export class TransactionBuilder {
options?: TransactionBuilder.TransactionBuilderOptions
);
addOperation(operation: xdr.Operation): this;
addOperationAt(op: xdr.Operation, i: number): this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it getting to point where it's worthwhile to add ts tests, index.d.test.ts? how do we know addOperation will work when used by a client, or is there some base validation done in build pipeline?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's JS unit tests for it but you're right that we should generally add more to the types/test.ts file. Unfortunately said tests only fail when you, well, add to them, and if you're adding to them then you're adding to the index.d.ts file anyway, so it wouldn't have prevented this slip-up (which came from an external contributor anyway).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the typing tests in c5c5f9b!

clearOperations(): this;
clearOperationAt(i: number): this;
addMemo(memo: Memo): this;
setTimeout(timeoutInSeconds: number): this;
setTimebounds(min: Date | number, max: Date | number): this;
Expand All @@ -1085,6 +1088,7 @@ export class TransactionBuilder {
envelope: string | xdr.TransactionEnvelope,
networkPassphrase: string
): Transaction | FeeBumpTransaction;

}

export namespace TransactionBuilder {
Expand Down
6 changes: 4 additions & 2 deletions types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ const transaction = new StellarSdk.TransactionBuilder(account, {
minAmountA: "10000",
minAmountB: "20000",
})
).addOperation(
).addOperationAt(
StellarSdk.Operation.setOptions({
setFlags: (StellarSdk.AuthImmutableFlag | StellarSdk.AuthRequiredFlag) as StellarSdk.AuthFlag,
clearFlags: (StellarSdk.AuthRevocableFlag | StellarSdk.AuthClawbackEnabledFlag) as StellarSdk.AuthFlag,
})
}),
0
).clearOperationAt(2
).addMemo(new StellarSdk.Memo(StellarSdk.MemoText, 'memo'))
.setTimeout(5)
.setTimebounds(Date.now(), Date.now() + 5000)
Expand Down
Loading