I’m attempting to create a TypeScript API that returns a function with additional properties. This function also needs to have its Function.prototype
properties removed. I have tried various combinations of Omit
, Pick
, etc., but haven’t been able to achieve the desired result.
My code so far is shown below:
type MainFunc = () => PublicInterface
type PublicFunction = () => PublicInterface
interface PublicInterface extends MainFunc {
mainFunc: MainFunc
anotherFunc: PublicFunction
}
const removeProto = (func: MainFunc) => {
Object.setPrototypeOf(func, null)
return func
}
const mainFunc: MainFunc = (): PublicInterface => createPublicInterface()
const anotherFunc: PublicFunction = () => createPublicInterface()
const createPublicInterface = (): PublicInterface =>
Object.assign(
removeProto(mainFunc),
{
mainFunc,
anotherFunc
}
)
How can I create a type that is a function and correctly omits Function.prototype
properties?