2023-08-17 04:46:10 +00:00
|
|
|
import {ReflectionFunction, stringifyType, typeOf} from '@deepkit/type'
|
|
|
|
import type {Dependencies, Signature, Signatures, OneType} from '../interfaces/type.js'
|
|
|
|
|
|
|
|
interface LocalSignatures<T> {
|
|
|
|
one: (a: T) => OneType<T>
|
|
|
|
}
|
2023-01-22 01:34:57 +00:00
|
|
|
|
|
|
|
export const square =
|
|
|
|
<T>(dep: Dependencies<'multiply', T>): Signature<'square', T> =>
|
|
|
|
z => dep.multiply(z, z)
|
2023-08-17 04:46:10 +00:00
|
|
|
|
|
|
|
const sqRefl = ReflectionFunction.from(square)
|
|
|
|
console.log(
|
|
|
|
' For generic square I know that:',
|
|
|
|
sqRefl,
|
|
|
|
sqRefl.getParameterNames(),
|
|
|
|
sqRefl.getParameterType('dep'),
|
|
|
|
"\n final dep type:",
|
|
|
|
stringifyType(sqRefl.getParameterType('dep')))
|
|
|
|
|
|
|
|
console.log(' because', typeOf<LocalSignatures<number>['one']>())
|
|
|
|
console.log(' readable:', stringifyType(typeOf<LocalSignatures<number>['one']>()))
|