32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import {Dispatcher} from './core/Dispatcher.js'
|
|
import * as Specifications from './all.js'
|
|
|
|
export default new Dispatcher(Specifications)
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
console.log('Dependencies of square are', Specifications.generic.square.dependencies)
|
|
console.log('Signature of square is', Specifications.generic.square.signature)
|
|
|
|
const realSquare = Specifications.generic.square<number>({multiply: (a,b) => a*b})
|
|
console.log('Square of 2.5 is', realSquare(2.5))
|
|
|
|
// and note the following fail with a type error as desired:
|
|
// const fakeSquare = Specifications.generic.square<number>({multiply: (a,b,c) => a*b*c})
|
|
// const stringSquare = Specifications.generic.square<string>({multiply: (a,b) => a*b})
|
|
// console.log('Square of three is', stringSquare('three'))
|