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

TransactionMetadatum.as_* methods: wrong type annotation #662

Closed
klntsky opened this issue Jan 24, 2024 · 1 comment
Closed

TransactionMetadatum.as_* methods: wrong type annotation #662

klntsky opened this issue Jan 24, 2024 · 1 comment

Comments

@klntsky
Copy link

klntsky commented Jan 24, 2024

declare export class TransactionMetadatum {
  free(): void;

  /**
   * @returns {Uint8Array}
   */
  to_bytes(): Uint8Array;

  /**
   * @param {Uint8Array} bytes
   * @returns {TransactionMetadatum}
   */
  static from_bytes(bytes: Uint8Array): TransactionMetadatum;

  /**
   * @returns {string}
   */
  to_hex(): string;

  /**
   * @param {string} hex_str
   * @returns {TransactionMetadatum}
   */
  static from_hex(hex_str: string): TransactionMetadatum;

  /**
   * @param {MetadataMap} map
   * @returns {TransactionMetadatum}
   */
  static new_map(map: MetadataMap): TransactionMetadatum;

  /**
   * @param {MetadataList} list
   * @returns {TransactionMetadatum}
   */
  static new_list(list: MetadataList): TransactionMetadatum;

  /**
   * @param {Int} int
   * @returns {TransactionMetadatum}
   */
  static new_int(int: Int): TransactionMetadatum;

  /**
   * @param {Uint8Array} bytes
   * @returns {TransactionMetadatum}
   */
  static new_bytes(bytes: Uint8Array): TransactionMetadatum;

  /**
   * @param {string} text
   * @returns {TransactionMetadatum}
   */
  static new_text(text: string): TransactionMetadatum;

  /**
   * @returns {number}
   */
  kind(): number;

  /**
   * @returns {MetadataMap}
   */
  as_map(): MetadataMap;

  /**
   * @returns {MetadataList}
   */
  as_list(): MetadataList;

  /**
   * @returns {Int}
   */
  as_int(): Int;

  /**
   * @returns {Uint8Array}
   */
  as_bytes(): Uint8Array;

  /**
   * @returns {string}
   */
  as_text(): string;
}

as_* methods should return X | void (they are all partial)

@lisicky
Copy link
Contributor

lisicky commented Jan 25, 2024

Hi @klntsky ! From wasm bingen side it is correct behavior, because as_* functions returns Result type it means you always get a non-nullable value or get an exception. In other words Result means for bingen return value or throw an exception.
Yes it is not the best logic for an as_* function but it is open source project and you can contribute. But changing from Result to Option leads API breaking changes and we can accept this change only for the next major version

@lisicky lisicky closed this as completed Aug 28, 2024
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

No branches or pull requests

2 participants