I was playing around with TypeScript and found that applying Omit<T, K> on a callable function, makes it no longer callable:
declare function myCallableFunction(): void;
myCallableFunction(); // valid
type NonOmittedFunction = typeof myCallableFunction;
declare const myNonOmittedFunction: NonOmittedFunction;
myNonOmittedFunction(); // valid
type OmittedFunction = Omit<typeof myCallableFunction, 'foobar'>;
declare const myOmittedFunction: OmittedFunction;
myOmittedFunction(); // This expression is not callable.
// Type 'OmittedFunction' has no call signatures.
Why is this?
Here is a heavily contrived example as to where you may want to do something like this:
declare type CallCountingFunction = (() => void) & { count: number }
const myFunction: CallCountingFunction = (() => {
const x = () => {};
x.count = 0;
return x;
})()
myFunction.count; // valid
myFunction() // valid
type OmittedFunction = Omit<CallCountingFunction, 'count'>;
declare const myOmittedFunction: OmittedFunction;
myOmittedFunction(); // This expression is not callable.
// Type 'OmittedFunction' has no call signatures.
This appears to be true for all generic utility types that involve remapping such as Partial<T> and Required<T>.