import { Extension } from './extension' ; import { isFunction } from './method/function' ; type AsMockedPropertyHandler < TMockedPropertyHandler , TMock , TPropName extends keyof TMock > = ( prop : TMock [ TPropName ] , mock : TMock , propName : TPropName ) => TMockedPropertyHandler ; export class ExtensionHandler < TMock > { private readonly _mock : TMock ; constructor ( mock ) { this . _mock = mock ; } public get < TPropName extends keyof TMock , TMockedPropertyHandler > ( propertyName , asMockedPropertyHandler ) ; public get < TMockedPropertyHandler > ( extension ) ; public get < TPropName extends keyof TMock , TMockedPropertyHandler > ( extensionOrPropertyName , maybePropertyHandler ? ) { if ( isFunction ( extensionOrPropertyName ) ) { return extensionOrPropertyName ( this . _mock ) ; } if ( ! maybePropertyHandler ) { throw new Error ( `It looks like you are trying to get an extension for ${ extensionOrPropertyName as string } without specifying the handler.` ) ; } return maybePropertyHandler ( this . _mock [ extensionOrPropertyName ] , this . _mock , extensionOrPropertyName ) ; } }