Skip to content

fix(ts): support nested option serialization#4584

Closed
abhinavgautam01 wants to merge 1 commit into
otter-sec:masterfrom
abhinavgautam01:fix/2435-nested-option-serialization
Closed

fix(ts): support nested option serialization#4584
abhinavgautam01 wants to merge 1 commit into
otter-sec:masterfrom
abhinavgautam01:fix/2435-nested-option-serialization

Conversation

@abhinavgautam01
Copy link
Copy Markdown
Contributor

Fixes #2435

Summary

Adds an explicit borsh.some(value) helper so TypeScript clients can serialize nested options where the outer option is Some and the inner option is None.

Previously, null always encoded as None, so Option<Option<T>> could encode:

  • None
  • Some(Some(value))

but could not represent:

  • Some(None)

With this change, callers can now encode Some(None) using:

borsh.some(null)

Testing

  • yarn build in ts/packages/borsh
  • yarn jest tests/coder-instructions.spec.ts --runInBand
  • yarn build:node in ts/packages/anchor
  • yarn test --runInBand in ts/packages/anchor

Comment thread ts/packages/borsh/src/index.ts
@abhinavgautam01 abhinavgautam01 force-pushed the fix/2435-nested-option-serialization branch from 7fa6993 to aa4caf1 Compare May 26, 2026 13:47
@jamie-osec
Copy link
Copy Markdown
Collaborator

I'm not super happy with this approach, as the decode change means a small breaking change and it just papers over an API design issue. I'm going to close this for now, but consider a PR to anchor-next which makes this API more intuitive

@jamie-osec jamie-osec closed this May 26, 2026
@abhinavgautam01
Copy link
Copy Markdown
Contributor Author

I'm not super happy with this approach, as the decode change means a small breaking change and it just papers over an API design issue. I'm going to close this for now, but consider a PR to anchor-next which makes this API more intuitive

thanks, that makes sense... i agree this is better handled as an API design change rather than trying to patch the current v1 behavior with a wrapper...

i will leave this PR closed and, if i pick this back up, i will target anchor-next with a cleaner nested option API instead of changing decode semantics in v1...

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.

Nested Option cannot be serialized from TS client

2 participants