Skip to content

Migrate memo.js to TS#873

Merged
Ryang-21 merged 7 commits intotypescript-migrationfrom
tsm-memo
Feb 26, 2026
Merged

Migrate memo.js to TS#873
Ryang-21 merged 7 commits intotypescript-migrationfrom
tsm-memo

Conversation

@Ryang-21
Copy link
Contributor

No description provided.

@Ryang-21 Ryang-21 linked an issue Feb 23, 2026 that may be closed by this pull request
5 tasks
@github-actions
Copy link

github-actions bot commented Feb 23, 2026

Size Change: +7.01 kB (+0.2%)

Total Size: 3.54 MB

Filename Size Change
dist/stellar-base.js 2.61 MB +5.18 kB (+0.2%)
dist/stellar-base.min.js 929 kB +1.83 kB (+0.2%)

compressed-size-action

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the memo.js file to TypeScript, converting it to src/memo.ts and updating the associated test file from JavaScript/Mocha to TypeScript/Vitest. The migration adds comprehensive type definitions including a generic Memo class with type-safe memo types and values.

Changes:

  • Migrated src/memo.js to src/memo.ts with full TypeScript type annotations and generic types
  • Converted test file from test/unit/memo_test.js (Mocha/Chai) to test/unit/memo.test.ts (Vitest)
  • Generated type definition file type_validation/memo.d.ts

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
src/memo.ts Migrated to TypeScript with generic types, updated XDR union handling from .arm() to .switch(), added type annotations for all methods
test/unit/memo_test.js Removed (replaced by TypeScript version)
test/unit/memo.test.ts New TypeScript test file using Vitest framework, maintains all test coverage from original file
type_validation/memo.d.ts Generated TypeScript type definitions matching the implementation
Comments suppressed due to low confidence (2)

src/memo.ts:262

  • The double conversion from string to UnsignedHyper and back to string before creating Uint64 appears redundant. This can be simplified to xdr.Memo.memoId(xdr.Uint64.fromString(this._value as string)) which matches the pattern used elsewhere in the codebase (see src/keypair.js:146, src/muxed_account.js:104, src/util/decode_encode_muxed_account.ts:69). The current implementation performs unnecessary conversions that impact performance.
    src/memo.ts:291
  • The switch statement is missing an explicit case for xdr.MemoType.memoNone(). While the current implementation works by falling through to the default case and checking if object.value() is undefined, it would be clearer and more maintainable to add an explicit case: case xdr.MemoType.memoNone(): return Memo.none(); before the default case. This makes the intent explicit and matches the pattern used in similar code throughout the codebase.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

src/memo.ts Outdated
Comment on lines 27 to 33
export namespace MemoType {
export type None = typeof MemoNone;
export type ID = typeof MemoID;
export type Text = typeof MemoText;
export type Hash = typeof MemoHash;
export type Return = typeof MemoReturn;
}
Copy link
Contributor

@quietbits quietbits Feb 25, 2026

Choose a reason for hiding this comment

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

I'm not sure if this would generate namespace output we currently have, but we could do it this way without using namespace. It sounds like using TS namespace is not recommended.

export type MemoTypeNone = typeof MemoNone;
export type MemoTypeID = typeof MemoID;
export type MemoTypeText = typeof MemoText;
export type MemoTypeHash = typeof MemoHash;
export type MemoTypeReturn = typeof MemoReturn;

src/memo.ts Outdated
Comment on lines 35 to 40
export type MemoType =
| MemoType.Hash
| MemoType.ID
| MemoType.None
| MemoType.Return
| MemoType.Text;
Copy link
Contributor

Choose a reason for hiding this comment

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

The this would be:

export type MemoType =
  | MemoTypeNone
  | MemoTypeID
  | MemoTypeText
  | MemoTypeHash
  | MemoTypeReturn;

src/memo.ts Outdated
Comment on lines 44 to 54
type MemoTypeToValue<T extends MemoType> = T extends MemoType.None
? null
: T extends MemoType.ID
? string
: T extends MemoType.Text
? Buffer | string
: T extends MemoType.Hash
? Buffer
: T extends MemoType.Return
? Buffer
: MemoValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Then we could make this part easier to read as well.

type MemoValueMap = {
  [MemoNone]: null;
  [MemoID]: string;
  [MemoText]: Buffer | string;
  [MemoHash]: Buffer;
  [MemoReturn]: Buffer;
};

type MemoTypeToValue<T extends MemoType> = MemoValueMap[T];

@Ryang-21 Ryang-21 merged commit b263c24 into typescript-migration Feb 26, 2026
6 checks passed
@Ryang-21 Ryang-21 deleted the tsm-memo branch February 26, 2026 19:33
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.

Migrate memo.js file to TS

3 participants