Creating a custom Data Converter on Temporal

Hi everyone! I started working with Temporal recently and one of the problems I was having is that many of my activities perform calculations using JS’s BigInt instead of the regular Number. The problem is that Temporal always serialize data, and BigInt is not serializable with the default JSON library.

I know Temporal allows for custom data converters, but i’m having a really hard time implementing one. I wanna keep using the default JSON library, but pass a simple replacer to be used when the type of something is BigInt. From my understanding, I just need to override the toPayload method from the converter. What I’ve done so far is:

import {
  Payload,
  METADATA_ENCODING_KEY,
  encodingKeys,
  PayloadConverter,
  ValueError,
} from '@temporalio/common';
import { decode, encode } from '@temporalio/common/lib/encoding';

const replacer = (_, value) => {
  if (typeof value === 'bigint') {
    return Number(value);
  }
  return value;
};

export class BigIntPayloadConverter implements PayloadConverter {
  /**
   * Serializes a value to a Payload
   */
  toPayload(value: unknown): Payload | undefined {
    if (value === undefined) {
      return undefined;
    }

    let json;
    try {
      json = JSON.stringify(value, replacer);
    } catch (_err) {
      return undefined;
    }

    return {
      metadata: {
        [METADATA_ENCODING_KEY]: encodingKeys.METADATA_ENCODING_JSON,
      },
      data: encode(json),
    };
  }

  public fromPayload<T>(content: Payload): T {
    if (content.data === undefined || content.data === null) {
      throw new ValueError('Got payload with no data');
    }
    return JSON.parse(decode(content.data));
  }
}

// Export the payload converter instance
export const payloadConverter = new BigIntPayloadConverter();

Although it seems fine, I get an error "Activity completions must contain a result payload on the workers. So my questions are:

1 - What is the simplest way to achieve this? A simple Data Converter that converts BigInt to Number (I know about the loss of precision, and thats not a concern for us).

2 - What interface or class should I implement or extend? Is it really the PayloadConverter?

Thanks!