You should get the following error:
Property 'update' in type 'SubClass' is not assignable to the same property in base type 'MyClass'.
Type '(id: ID, obj: HashMap) => void' is not assignable to type '{ (obj: HashMap): any; (id: ID, obj: HashMap): any; }'.
The reason for this is that when overriding a method, it has to have the exact same type as the original method. Since the method in MyClass is an overloaded type, it has two alternative types. But the overriden method only has one.
So you need to specify the exact same overloads, even if you don’t need them in the subtype:
class SubClass extends MyClass {
update(obj: HashMap);
update(id: ID, obj: HashMap);
update(objOrId: HashMap | ID, obj?: HashMap) {
console.log('here I want to use both params');
}
}
Remember that TypeScript will actually only emit the final function definition, and there is no run-time validation for the parameter types. So you will still have to handle the case that just a HashMap will be passed to your SubClass instance. This is especially true if you consider the Liskov substitution principle which also requires that any instance of SubClass can be used as a MyClass instance; so passing just a HashMap is absolutely fine.
Example on TypeScript playground