feat(PocomathInstance): Add .returnTypeOf method
This commit is contained in:
parent
95f6ccc5a0
commit
340dbd436e
2 changed files with 15 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
|||
import typed from 'typed-function'
|
||||
import {makeChain} from './Chain.mjs'
|
||||
import {dependencyExtractor, generateTypeExtractor} from './extractors.mjs'
|
||||
import R_ from './returns.mjs'
|
||||
import {R_, returnTypeOf} from './returns.mjs'
|
||||
import {typeListOfSignature, typesOfSignature, subsetOfKeys} from './utils.mjs'
|
||||
|
||||
const anySpec = {} // fixed dummy specification of 'any' type
|
||||
|
@ -191,6 +191,16 @@ export default class PocomathInstance {
|
|||
return result
|
||||
}
|
||||
|
||||
/* Determine the return type of an operation given an input signature */
|
||||
returnTypeOf(operation, signature) {
|
||||
if (typeof operation === 'string') {
|
||||
operation = this[operation]
|
||||
}
|
||||
if (!(this._typed.isTypedFunction(operation))) return 'any'
|
||||
const details = this._typed.findSignature(operation, signature)
|
||||
return returnTypeOf(details.fn)
|
||||
}
|
||||
|
||||
/* Return a chain object for this instance with a given value: */
|
||||
chain(value) {
|
||||
return makeChain(value, this, this._chainRepository)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue