wip: add getExtensionField

This commit is contained in:
Philipp Kühn
2021-04-15 21:14:33 +02:00
parent d194b90a61
commit 07bc40ce75
11 changed files with 213 additions and 274 deletions

View File

@@ -1,3 +1,5 @@
import { MaybeReturnType } from '../types'
/**
* Optionally calls `value` as a function.
* Otherwise it is returned directly.
@@ -5,7 +7,7 @@
* @param context Optional context to bind to function.
* @param props Optional props to pass to function.
*/
export default function callOrReturn(value: any, context: any = undefined, ...props: any[]): any {
export default function callOrReturn<T>(value: T, context: any = undefined, ...props: any[]): MaybeReturnType<T> {
if (typeof value === 'function') {
if (context) {
return value.bind(context)(...props)
@@ -14,5 +16,5 @@ export default function callOrReturn(value: any, context: any = undefined, ...pr
return value(...props)
}
return value
return value as MaybeReturnType<T>
}