fix: generate CommonJS output instead of ESM as a workaround for typescript-rtti issue #94
This commit is contained in:
parent
5872bd8537
commit
86688ca129
5 changed files with 38 additions and 14 deletions
43
src/index.ts
43
src/index.ts
|
@ -1,10 +1,11 @@
|
|||
import 'reflect-metadata'
|
||||
|
||||
import {Dispatcher} from './core/Dispatcher.js'
|
||||
import * as Specifications from './all.js'
|
||||
import {Complex} from './Complex/type.js'
|
||||
import {absquare as absquare_complex} from './Complex/arithmetic.js'
|
||||
|
||||
import 'reflect-metadata'
|
||||
import { ReflectedFunctionParameter, ReflectedObjectRef, reflect } from 'typescript-rtti'
|
||||
import { CallSite, ReflectedObjectRef, reflect } from 'typescript-rtti'
|
||||
import { square } from './generic/arithmetic.js'
|
||||
|
||||
// verify that typescript-rtti works (just as experiment)
|
||||
|
@ -21,29 +22,55 @@ console.log()
|
|||
// returnType class Number
|
||||
|
||||
// try out a very simple case (just as experiment)
|
||||
function createSquare(deps: {
|
||||
multiply: (a: number, b: number) => number,
|
||||
subtract: (a: number, b: number) => number
|
||||
function createSquare(deps: {
|
||||
multiply: (a: number, b: number) => number,
|
||||
subtract: (a: number, b: number) => number
|
||||
}) {
|
||||
return (a: number) => deps.multiply(a, a)
|
||||
}
|
||||
console.log('reflect createSquare')
|
||||
console.log('parameter names', reflect(createSquare).parameters.map(parameter => parameter.name))
|
||||
console.log('parameter[0]', (reflect(createSquare).parameters[0] as ReflectedFunctionParameter))
|
||||
// console.log('parameter[0]', (reflect(createSquare).parameters[0] as ReflectedFunctionParameter))
|
||||
// @ts-ignore
|
||||
console.log('parameterTypes[0]', (reflect(createSquare).parameterTypes[0] as ReflectedObjectRef)._ref.m)
|
||||
console.log('parameterTypes[0][0]',
|
||||
console.log('parameterTypes[0].ref.m[0]',
|
||||
// @ts-ignore
|
||||
(reflect(createSquare).parameterTypes[0] as ReflectedObjectRef)._ref.m[0].n,
|
||||
// @ts-ignore
|
||||
(reflect(createSquare).parameterTypes[0] as ReflectedObjectRef)._ref.m[0]
|
||||
)
|
||||
console.log('parameterTypes[0].ref.m[0].t.m',
|
||||
// @ts-ignore
|
||||
(reflect(createSquare).parameterTypes[0] as ReflectedObjectRef)._ref.m[0].t.m
|
||||
)
|
||||
// @ts-ignore
|
||||
console.log('parameters[0]', reflect(createSquare).parameters[0])
|
||||
// console.log('parameters[0]', reflect(createSquare).parameters[0])
|
||||
// FIXME: where to find the information of the types of the dependencies multiply and subtract?
|
||||
|
||||
// Test whether we loose the type information when casting to a generic interface
|
||||
// Conclusion: we keep the information, that is good.
|
||||
console.log()
|
||||
console.log('reflect createFunction')
|
||||
type MathjsDependencies = Record<string, Function>
|
||||
type MathjsCreateFunction = (deps: MathjsDependencies) => Function
|
||||
const createFunction: MathjsCreateFunction = createSquare as MathjsCreateFunction
|
||||
console.log('parameter names', reflect(createFunction).parameters.map(parameter => parameter.name))
|
||||
// @ts-ignore
|
||||
console.log('parameterTypes[0]', (reflect(createFunction).parameterTypes[0] as ReflectedObjectRef)._ref.m)
|
||||
|
||||
|
||||
|
||||
console.log()
|
||||
console.log('CallSite')
|
||||
function foo<T>(call? : CallSite) {
|
||||
console.log(reflect(call).typeParameters[0].isClass(String))
|
||||
}
|
||||
|
||||
function bar<T>(call? : CallSite) {
|
||||
foo<T>();
|
||||
}
|
||||
bar<String>();
|
||||
|
||||
// FIXME: get all types out of Specifications
|
||||
// console.log('Specifications', reflect(Specifications)) // Throws errors
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue