2023-08-15 23:50:24 +00:00
|
|
|
import {
|
|
|
|
typeOf, ReflectionFunction, ReflectionClass, ReflectionKind, stringifyType
|
|
|
|
} from '@deepkit/type'
|
|
|
|
|
2022-12-07 01:21:05 +00:00
|
|
|
import {Dispatcher} from './core/Dispatcher.js'
|
|
|
|
import * as Specifications from './all.js'
|
2022-12-06 17:10:18 +00:00
|
|
|
|
|
|
|
export default new Dispatcher(Specifications)
|
2023-01-22 01:34:57 +00:00
|
|
|
|
|
|
|
import {Complex} from './Complex/type.js'
|
|
|
|
import {absquare as absquare_complex} from './Complex/arithmetic.js'
|
|
|
|
|
|
|
|
const mockRealAdd = (a: number, b: number) => a+b
|
|
|
|
const mockComplexAbsquare = (z: Complex<number>) => z.re*z.re + z.im*z.im
|
|
|
|
|
2023-08-15 23:50:24 +00:00
|
|
|
const addRefl = ReflectionFunction.from(mockRealAdd)
|
|
|
|
|
|
|
|
console.log('----> I figured out:', addRefl, addRefl.getParameterNames(), addRefl.getParameterType('b'))
|
|
|
|
|
|
|
|
function bungle(deps: {
|
|
|
|
factor: (i: number) => number,
|
|
|
|
label: string
|
|
|
|
}) {
|
|
|
|
return (a: number) => deps.label + (deps.factor(2)*a)
|
|
|
|
}
|
|
|
|
|
|
|
|
let fn = (i:number) => 3*i
|
|
|
|
console.log("\nBungling", bungle({factor: fn, label:'hextupled: '})(7))
|
|
|
|
const bRefl = ReflectionFunction.from(bungle)
|
|
|
|
const depstype = bRefl.getParameterType('deps')
|
|
|
|
console.log('Deps type is', depstype)
|
|
|
|
console.log(' aka ', stringifyType(depstype))
|
|
|
|
if (depstype.kind == ReflectionKind.objectLiteral) {
|
|
|
|
const depsRefl = new ReflectionClass(depstype)
|
|
|
|
console.log(' With methods', depsRefl.getMethodNames())
|
|
|
|
const factorRefl = depsRefl.getMethod('factor')
|
|
|
|
console.log(' And factor method takes parameters',
|
|
|
|
factorRefl.getParameterNames())
|
|
|
|
const itype = factorRefl.getParameterType('i')
|
|
|
|
console.log(' Parameter `i` has type', itype)
|
|
|
|
console.log(' aka', stringifyType(itype))
|
|
|
|
} else {
|
|
|
|
console.log(' Not understanding deps')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-22 01:34:57 +00:00
|
|
|
const quatAbsquare = absquare_complex({
|
|
|
|
add: mockRealAdd,
|
|
|
|
absquare: mockComplexAbsquare
|
|
|
|
})
|
|
|
|
|
|
|
|
const myabs = quatAbsquare({re: {re: 0, im: 1}, im: {re:2, im: 3}})
|
|
|
|
const typeTest: typeof myabs = 7 // check myabs is just a number
|
|
|
|
|
|
|
|
console.log('Result is', myabs)
|