Binding to libraries that expect classical inheritance as a fundamental part of their API

I’m writing bindings for slash-create. However, it uses inheritance as a core element of its API — you’re expected to create “command” classes that inherit from their core SlashCommand class, and pass an array of such classes to another part of the API:

// index.js
const { Creator } = require('slash-create');
const path = require('path');
const creator = new Creator({
  applicationID: '12345678901234567',
  publicKey: 'CLIENT_PUBLIC_KEY',
  token: 'BOT_TOKEN_HERE',

    // Registers all of your commands in the ./commands/ directory
    .registerCommandsIn(path.join(__dirname, 'commands'))
    // This will sync commands to Discord, it must be called after commands are loaded.
    // This also returns itself for more chaining capabilities.
// commands/hello.js
const { SlashCommand, CommandOptionType } = require('slash-create');

module.exports = class HelloCommand extends SlashCommand {
  constructor(creator) {
    super(creator, {
      name: 'hello',
      description: 'Says hello to you.',
      options: [{
        type: CommandOptionType.STRING,
        name: 'food',
        description: 'What food do you like?'

    // Not required initially, but required for reloading with a fresh file.
    this.filePath = __filename;

  async run(ctx) {
    return ? `You like ${}? Nice!` : `Hello, ${ctx.user.username}!`;

I’m substantially compfortable with both OCaml and JS separately, and not entirely new to writing BuckleScript bindings; but I have to admit I’m not sure of a beautiful way to map this behaviour onto OCaml.

Anybody have any ideas? What would you consider the most idiomatic way to map this behaviour?

I don’t think there’s a better way than %%raw. ReScript doesn’t support JavaScript inheritance, and binding to prototypal inheritance is really ugly:

1 Like