fix: generate CommonJS output instead of ESM as a workaround for typescript-rtti issue #94
This commit is contained in:
parent
5872bd8537
commit
86688ca129
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,8 +2,7 @@
|
||||
*~
|
||||
# Typescript
|
||||
# emitted code
|
||||
build/*
|
||||
!build/package.json
|
||||
build
|
||||
|
||||
# ---> Node
|
||||
# Logs
|
||||
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
@ -20,12 +20,12 @@
|
||||
},
|
||||
dependencies: {
|
||||
'reflect-metadata': '0.1.13',
|
||||
'typescript-rtti': '0.8.3',
|
||||
},
|
||||
devDependencies: {
|
||||
'@types/node': '18.11.18',
|
||||
'ts-node': '10.9.1',
|
||||
ttypescript: '1.5.15',
|
||||
typescript: '4.7.4',
|
||||
'typescript-rtti': '0.8.3',
|
||||
},
|
||||
}
|
||||
|
37
src/index.ts
37
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)
|
||||
@ -29,21 +30,47 @@ function createSquare(deps: {
|
||||
}
|
||||
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
|
||||
console.log('parameters[0]', reflect(createSquare).parameters[0])
|
||||
(reflect(createSquare).parameterTypes[0] as ReflectedObjectRef)._ref.m[0].t.m
|
||||
)
|
||||
// @ts-ignore
|
||||
// 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
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
"allowJs": false,
|
||||
"noImplicitAny": false,
|
||||
"moduleResolution": "Node",
|
||||
"module": "commonjs",
|
||||
"plugins": [
|
||||
{
|
||||
"transform": "typescript-rtti/dist/transformer"
|
||||
|
Loading…
Reference in New Issue
Block a user