issue: deepkit punts on complicated template instantions/intersections

The most troubling example is found in `src/complex/arithmetic.ts`,
  where (as one can see by carefully screening the output when you
  run src/index.ts) deepkit reports the type of

  ```
  Dependencies<'absquare', X> & Dependencies<'add', Returns<'absquare', X>>
  ```

  to be `any` (look for the line starting "Because { kind: 1," in the output;
  kind: 1 is deepkit's code for `any`. It doesn't even give a syntactic
  description of the type as say the intersection of two instances of the
  Dependencies generic type, which would be good enough (if we got the
  string parameters to the generics).
This commit is contained in:
Glen Whitney 2023-08-16 12:57:48 -07:00
parent eff68e5ac2
commit 58f0250ab4
3 changed files with 28 additions and 3 deletions

View File

@ -1,3 +1,4 @@
import {ReflectionFunction, stringifyType, typeOf} from '@deepkit/type'
import {Complex} from './type.js'
import type {
Dependencies, Signature, Returns, RealType, AliasOf
@ -53,6 +54,13 @@ export const absquare =
Signature<'absquare', Complex<T>> =>
z => dep.add(dep.absquare(z.re), dep.absquare(z.im))
const asRefl = ReflectionFunction.from(absquare)
console.log(' Here I only know that:', asRefl, asRefl.getParameterNames(), asRefl.getParameterType('dep'), stringifyType(asRefl.getParameterType('dep')))
class X {}
console.log(' Because', typeOf<Dependencies<'absquare', X> & Dependencies<'add', Returns<'absquare', X>>>())
export const divideReal =
<T>(dep: Dependencies<'divideReal' | 'complex', T>):
Signature<'divideReal', Complex<T>> =>

View File

@ -33,7 +33,7 @@ type TypeSpecification = {
}
type SpecObject = Record<string, Function | TypeSpecification>
type SpecificationsGroup = Record<string, SpecObject>
export type SpecificationsGroup = Record<string, SpecObject>
export class Dispatcher {
installSpecification(

View File

@ -1,10 +1,27 @@
import {
typeOf, ReflectionFunction, ReflectionClass, ReflectionKind, stringifyType
typeOf, ReflectionFunction, ReflectionClass, ReflectionKind, stringifyType,
ReceiveType, resolveReceiveType
} from '@deepkit/type'
import {Dispatcher} from './core/Dispatcher.js'
import {SpecificationsGroup, Dispatcher} from './core/Dispatcher.js'
import * as Specifications from './all.js'
const asRefl = ReflectionFunction.from(Specifications.complex.absquare)
console.log(' all I know is:', asRefl, asRefl.getParameterNames(), asRefl.getParameterType('dep'))
function analyze<SpecType>(
spec: SpecificationsGroup, type?: ReceiveType<SpecType>
) {
type = resolveReceiveType(type)
console.log(stringifyType(type))
console.log('is the type of')
console.log(spec)
//@ts-ignore
console.log('In particular', spec.complex.absquare.__type)
}
analyze<typeof Specifications>(Specifications)
export default new Dispatcher(Specifications)
import {Complex} from './Complex/type.js'