Skip to main content
Deno 2 is finally here πŸŽ‰οΈ
Learn more

overloadpng A type-safe way to make overloads for your functions in Deno πŸš€

Getting Started

Import the overload library in your file:

import { overload } from 'https://deno.land/x/overload@2.0.0/mod.ts';

Then, you can get started overloading your functions!

Quick Examples

const concat = overload(
  "concat",
  {
    args: [String, String],
    func: (str1: String, str2: String) => {
      return `${str1}${str2}`;
    },
  },
  {
    args: [String, String, String],
    func: (str1: String, str2: String, str3: String) => {
      return `${str1}${str2}${str3}`;
    },
  },
);

console.log(concat("1", "2")); // 12
console.log(concat("1", "2", "3")); // 123
console.log(concat("1", "2", "3", 4)); // error

API

overload.overload(name: String, ...functions: OverloadFunction[]): Function

Parameters

name

The name of the function.

...functions

The functions that each represent an overload.

interface OverloadFunction

Properties

args: Function[]

The list of types for each parameter of the function.

func: Function

The function.