I keep getting following error:
error TS2394: Overload signature is not compatible with function implementation.
for following code:
import Registry = require('../class/Registry');
type Format = Function;
type FormatRegistry = {
[s: string]: Format;
}
var registry = new Registry<Format>();
function formatAPI(): FormatRegistry; // get all formats // HERE GOES THE COMPILER ERROR
function formatAPI(name: string): Format; // get format
function formatAPI(name: string, format: Format): void; // register format
function formatAPI(formatMap: FormatRegistry): void; // register many formats
function formatAPI(nameOrMap?: string|FormatRegistry, callback?: Format): FormatRegistry|Format|void {
if (typeof nameOrMap === 'object') {
registry.registerMany(nameOrMap);
} else if (typeof nameOrMap === 'string') {
if (callback) {
registry.register(nameOrMap, callback);
} else {
return registry.get(nameOrMap);
}
} else {
return registry.list();
}
}
export = formatAPI;
I can't see what is wrong in the function type overloading above. I tried to remove functions signatures (and according types) piece by piece but I failed - I achieved an empty function.
The logic behind the codeis fine (all tests pass), just the overloads are somehow invalid.
This question is related to this one.