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
|
# Typescript
|
||||||
# emitted code
|
# emitted code
|
||||||
build/*
|
build
|
||||||
!build/package.json
|
|
||||||
|
|
||||||
# ---> Node
|
# ---> Node
|
||||||
# Logs
|
# Logs
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "module"
|
|
||||||
}
|
|
@ -20,12 +20,12 @@
|
|||||||
},
|
},
|
||||||
dependencies: {
|
dependencies: {
|
||||||
'reflect-metadata': '0.1.13',
|
'reflect-metadata': '0.1.13',
|
||||||
|
'typescript-rtti': '0.8.3',
|
||||||
},
|
},
|
||||||
devDependencies: {
|
devDependencies: {
|
||||||
'@types/node': '18.11.18',
|
'@types/node': '18.11.18',
|
||||||
'ts-node': '10.9.1',
|
'ts-node': '10.9.1',
|
||||||
ttypescript: '1.5.15',
|
ttypescript: '1.5.15',
|
||||||
typescript: '4.7.4',
|
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 {Dispatcher} from './core/Dispatcher.js'
|
||||||
import * as Specifications from './all.js'
|
import * as Specifications from './all.js'
|
||||||
import {Complex} from './Complex/type.js'
|
import {Complex} from './Complex/type.js'
|
||||||
import {absquare as absquare_complex} from './Complex/arithmetic.js'
|
import {absquare as absquare_complex} from './Complex/arithmetic.js'
|
||||||
|
|
||||||
import 'reflect-metadata'
|
import { CallSite, ReflectedObjectRef, reflect } from 'typescript-rtti'
|
||||||
import { ReflectedFunctionParameter, ReflectedObjectRef, reflect } from 'typescript-rtti'
|
|
||||||
import { square } from './generic/arithmetic.js'
|
import { square } from './generic/arithmetic.js'
|
||||||
|
|
||||||
// verify that typescript-rtti works (just as experiment)
|
// verify that typescript-rtti works (just as experiment)
|
||||||
@ -29,21 +30,47 @@ function createSquare(deps: {
|
|||||||
}
|
}
|
||||||
console.log('reflect createSquare')
|
console.log('reflect createSquare')
|
||||||
console.log('parameter names', reflect(createSquare).parameters.map(parameter => parameter.name))
|
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
|
// @ts-ignore
|
||||||
console.log('parameterTypes[0]', (reflect(createSquare).parameterTypes[0] as ReflectedObjectRef)._ref.m)
|
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
|
// @ts-ignore
|
||||||
(reflect(createSquare).parameterTypes[0] as ReflectedObjectRef)._ref.m[0].n,
|
(reflect(createSquare).parameterTypes[0] as ReflectedObjectRef)._ref.m[0].n,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
(reflect(createSquare).parameterTypes[0] as ReflectedObjectRef)._ref.m[0]
|
(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
|
// @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?
|
// 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
|
// FIXME: get all types out of Specifications
|
||||||
// console.log('Specifications', reflect(Specifications)) // Throws errors
|
// console.log('Specifications', reflect(Specifications)) // Throws errors
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"allowJs": false,
|
"allowJs": false,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "Node",
|
||||||
|
"module": "commonjs",
|
||||||
"plugins": [
|
"plugins": [
|
||||||
{
|
{
|
||||||
"transform": "typescript-rtti/dist/transformer"
|
"transform": "typescript-rtti/dist/transformer"
|
||||||
|
Loading…
Reference in New Issue
Block a user