I know I can use declaration merging to add a new definition to built-in methods like this:
interface ObjectConstructor {
keys<T>(o: T & (T extends any[] ? never : object): string[];
}
I want this definition of Object.keys to disallow arrays. However, this adds a new overloaded definition to Object.keys, it doesn't remove the existing definitions. If I call Object.keys({}), it uses my new definition. If I call Object.keys([]), it skips my definition and uses the built-in definition.
Is there a way to delete the old definitions of Object.keys?
Edit: for this particular problem, I realized I could just do keys(o: any[]): never. However, it'll be useful to know a general solution.