Overload a Function with TypeScript’s Overload Signatures

InstructorMarius Schulz

Share this video with your friends

Send Tweet

Some functions may have different return types depending on the types of the arguments with which they’re invoked. Using TypeScript’s function overloads, you can create an overload for each allowed combination of parameter and return types. This way, all type-correct signatures of a function are encoded in the type system and can be surfaced by the TypeScript Language Service within your editor.

Leandro Fernandez
~ 6 years ago

Without the "target": "es2015" compiler option that example isnt working for me. Guess you forgot to mention that. Nice course man.

Ben Polinsky
~ 6 years ago

@Leandro +1

Also, vscode still complains for me (even though the code compiles) after I added the es2015 target.