0

Is function overloading not supported in TypeScript?

I have these two functions:

checkCredits() {
   // my code
}

checkCredits(header: any) {
    // my code
}

And I call the second function like this:

this.checkCredits(this.myObject); 

When compiling in vs code I get these errors: Supplied Parameters do not match any signature of call target. Duplicate function implementation.

1

1 Answer 1

2

Overloading in typescript is done by using optional parameters.

checkCredits(header?: any) {
    // my code
}

Now you can call:

this.checkCredits(this.myObject); 

and

this.checkCredits(); 

Downside you have the logic in the same function.You can check the issue

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I wasn't aware of that.
@Rich you can also do it this way. But didnt seem necessary in your example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.