typocomath/src/index.ts

38 lines
1.3 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)
// Check type of the generic square implementation
console.log('Type of square is', Specifications.generic.square.reflectedType)
// Now check the ones that came via macros:
// Auto-generated export is invisible to TypeScript at the moment, author
// says he will fix:
console.log('Type of squire (auto-exported) is',
// @ts-ignore
Specifications.generic.squire.reflectedType)
// Via a macro wrapper around the definition, two ways:
console.log('Type of squre (unexpanded) is',
Specifications.generic.squre.reflectedType)
console.log('Type of sqre (expanded) is',
Specifications.generic.sqre.reflectedType)