# Strange Errors with Function Overloading and Recursion

**URL:** <https://forum.makecode.com/t/strange-errors-with-function-overloading-and-recursion/31133>\
**Category:** Help\
**Created:** [October 11, 2024, 9:35pm UTC](https://forum.makecode.com/t/strange-errors-with-function-overloading-and-recursion/31133 "2024-10-11T21:35:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chembot](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/chembot/32/14245_2.png) [@chembot](https://forum.makecode.com/u/chembot)\
**Post date:** [October 11, 2024, 9:35pm UTC](https://forum.makecode.com/t/strange-errors-with-function-overloading-and-recursion/31133/1 "2024-10-11T21:35:58Z")

</div>

Midway through making this post I found that function overloading isn’t supported. Still found something interesting though, and had a question about a workaround.

I was trying to have a function in a class with different overloads. Here’s the code:

```auto
class Foo {
    public static bar(param1: number): string;
    public static bar(param1: string): string;
    public static bar(param1: number | string): string {
        if(typeof param1 === 'number') {
            // If it's a number, call again with param1 as a string.
            return Foo.bar(param1.toString());
        }
        // If it's a string, format it. 
        return "value: " + param1;
    }

```

This code gives the problem “!proc || !bin.finalPass”.  
When changing the function to be non-static:

```auto
class Foo {
    public bar(param1: number): string;
    public bar(param1: string): string;
    public bar(param1: number | string): string {
        if(typeof param1 === 'number') {
            // If it's a number, call again with param1 as a string.
            return this.bar(param1.toString());
        }
        // If it's a string, format it. 
        return "value: " + param1;
    }
}

```

It refused to compile. In the chrome console it gave this error:  
‘Uncaught (in promise) Error: TypeError: Cannot read properties of null (reading ‘info’)’  
This isn’t the full error, the stacktrace was kind of long.

I know that overloading isn’t supported, but I wanted to point this out since I spent a lot of time figuring out why it wouldn’t compile. Also, I tried not including the two overloads of bar and just having the `bar(param1: number | string)` and it seemed to work? Is this type of thing fine as a workaround to overloading? Thanks.
