Compare commits

...

6 Commits
main ... dktype

Author SHA1 Message Date
Glen Whitney 9abea5c484 issue: deepkit doesn't reflect types imported via `import type` 2023-08-16 21:46:10 -07:00
Glen Whitney 58f0250ab4 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).
2023-08-16 12:57:48 -07:00
Glen Whitney eff68e5ac2 doc: note possible need for extra installation step 2023-08-15 17:04:30 -07:00
Glen Whitney 479a484011 feat: Deepkit provides type info for case that typescript-rtti failed 2023-08-15 16:50:24 -07:00
Glen Whitney 16da30d865 doc: add command to create package.json in obj directory 2023-08-15 11:05:11 -07:00
Glen Whitney 7243277546 chore: update typescript to latest 2023-08-15 10:58:58 -07:00
10 changed files with 321 additions and 13 deletions

View File

@ -6,5 +6,8 @@ To build and run the prototype, run:
```
npx tsc
echo '{"type": "module"}' > obj/package.json
node obj
```
Installation note: after doing `pnpm install` if the above compilation/run commands don't seem to work, execute `npx deepkit-type-install` and try again.

View File

@ -18,6 +18,11 @@
url: 'https://code.studioinfinity.org/glen/typocomath.git',
},
devDependencies: {
typescript: '^4.9.3',
'@deepkit/type-compiler': '1.0.1-alpha.97',
'@types/node': '^20.5.0',
typescript: '^5.1.6',
},
dependencies: {
'@deepkit/type': '1.0.1-alpha.97',
},
}

View File

@ -1,15 +1,222 @@
lockfileVersion: 5.4
lockfileVersion: '6.0'
specifiers:
typescript: ^4.9.3
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
dependencies:
'@deepkit/type':
specifier: 1.0.1-alpha.97
version: 1.0.1-alpha.97(@deepkit/core@1.0.1-alpha.97)
devDependencies:
typescript: 4.9.3
'@deepkit/type-compiler':
specifier: 1.0.1-alpha.97
version: 1.0.1-alpha.97(typescript@5.1.6)
'@types/node':
specifier: ^20.5.0
version: 20.5.0
typescript:
specifier: ^5.1.6
version: 5.1.6
packages:
/typescript/4.9.3:
resolution: {integrity: sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==}
engines: {node: '>=4.2.0'}
/@deepkit/core@1.0.1-alpha.97:
resolution: {integrity: sha512-SrG9m43w+fJhiFH4wxyc6QNruFxJaqiGpT+QAncqR0dDvd+5QUCLwD2mGiKkNJoFh2lo+p3rtYhnZ0exny8emw==}
dependencies:
dot-prop: 5.3.0
to-fast-properties: 3.0.1
dev: false
/@deepkit/type-compiler@1.0.1-alpha.97(typescript@5.1.6):
resolution: {integrity: sha512-KeK21jdqM3keF504kmf7RcJkWV/xJMAjiK79MkNN43TyRjViOkmv50p6CW+vdHx6H772sQ765gX+gpH8i/yIZQ==}
hasBin: true
requiresBuild: true
peerDependencies:
typescript: ^4.8.2 || ^5.0.0
dependencies:
'@deepkit/type-spec': 1.0.1-alpha.93
'@marcj/ts-clone-node': 2.2.0(typescript@5.1.6)
'@typescript/vfs': 1.5.0
get-tsconfig: 4.7.0
lz-string: 1.5.0
micromatch: 4.0.5
strip-json-comments: 3.1.1
typescript: 5.1.6
transitivePeerDependencies:
- supports-color
dev: true
/@deepkit/type-spec@1.0.1-alpha.93:
resolution: {integrity: sha512-ZJHq0tOCYW0pDZ4Ab3RLQiFvDCTD2Dur+af4I0kmtT23slz+WWMNehJF08lO4DUDyOO0f0DlLLCqO39GhY3J4Q==}
/@deepkit/type@1.0.1-alpha.97(@deepkit/core@1.0.1-alpha.97):
resolution: {integrity: sha512-fnMrhMVYANyZ8zrKEj7KnJMTl2WhXKza9dh9s0Mtgcowd73YSJyEdvFkBKcabmHbvlbHFkAHv8KAvYifvWbGvw==}
peerDependencies:
'@deepkit/core': ^1.0.1-alpha.13
dependencies:
'@deepkit/core': 1.0.1-alpha.97
'@deepkit/type-spec': 1.0.1-alpha.93
'@types/uuid': 8.3.4
buffer: 5.7.1
uuid: 8.3.2
dev: false
/@marcj/ts-clone-node@2.2.0(typescript@5.1.6):
resolution: {integrity: sha512-72i531GZWaiHDvNZr0Fz+uiZMMyWzQqJxbhxD5g2dpU3eqEBk6p6mcDNBcOdiNhngAJ5Ebqv2krrs7MwuFg9rw==}
engines: {node: '>=14.9.0'}
dependencies:
compatfactory: 2.0.9(typescript@5.1.6)
transitivePeerDependencies:
- typescript
dev: true
/@types/node@20.5.0:
resolution: {integrity: sha512-Mgq7eCtoTjT89FqNoTzzXg2XvCi5VMhRV6+I2aYanc6kQCBImeNaAYRs/DyoVqk1YEUJK5gN9VO7HRIdz4Wo3Q==}
dev: true
/@types/uuid@8.3.4:
resolution: {integrity: sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==}
dev: false
/@typescript/vfs@1.5.0:
resolution: {integrity: sha512-AJS307bPgbsZZ9ggCT3wwpg3VbTKMFNHfaY/uF0ahSkYYrPF2dSSKDNIDIQAHm9qJqbLvCsSJH7yN4Vs/CsMMg==}
dependencies:
debug: 4.3.4
transitivePeerDependencies:
- supports-color
dev: true
/base64-js@1.5.1:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
dev: false
/braces@3.0.2:
resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==}
engines: {node: '>=8'}
dependencies:
fill-range: 7.0.1
dev: true
/buffer@5.7.1:
resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==}
dependencies:
base64-js: 1.5.1
ieee754: 1.2.1
dev: false
/compatfactory@2.0.9(typescript@5.1.6):
resolution: {integrity: sha512-fvO+AWcmbO7P1S+A3mwm3IGr74eHMeq5ZLhNhyNQc9mVDNHT4oe0Gg0ksdIFFNXLK7k7Z/TYcLAUSQdRgh1bsA==}
engines: {node: '>=14.9.0'}
peerDependencies:
typescript: '>=3.x || >= 4.x'
dependencies:
helpertypes: 0.0.19
typescript: 5.1.6
dev: true
/debug@4.3.4:
resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==}
engines: {node: '>=6.0'}
peerDependencies:
supports-color: '*'
peerDependenciesMeta:
supports-color:
optional: true
dependencies:
ms: 2.1.2
dev: true
/dot-prop@5.3.0:
resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==}
engines: {node: '>=8'}
dependencies:
is-obj: 2.0.0
dev: false
/fill-range@7.0.1:
resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==}
engines: {node: '>=8'}
dependencies:
to-regex-range: 5.0.1
dev: true
/get-tsconfig@4.7.0:
resolution: {integrity: sha512-pmjiZ7xtB8URYm74PlGJozDNyhvsVLUcpBa8DZBG3bWHwaHa9bPiRpiSfovw+fjhwONSCWKRyk+JQHEGZmMrzw==}
dependencies:
resolve-pkg-maps: 1.0.0
dev: true
/helpertypes@0.0.19:
resolution: {integrity: sha512-J00e55zffgi3yVnUp0UdbMztNkr2PnizEkOe9URNohnrNhW5X0QpegkuLpOmFQInpi93Nb8MCjQRHAiCDF42NQ==}
engines: {node: '>=10.0.0'}
dev: true
/ieee754@1.2.1:
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
dev: false
/is-number@7.0.0:
resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
engines: {node: '>=0.12.0'}
dev: true
/is-obj@2.0.0:
resolution: {integrity: sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==}
engines: {node: '>=8'}
dev: false
/lz-string@1.5.0:
resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==}
hasBin: true
dev: true
/micromatch@4.0.5:
resolution: {integrity: sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==}
engines: {node: '>=8.6'}
dependencies:
braces: 3.0.2
picomatch: 2.3.1
dev: true
/ms@2.1.2:
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
dev: true
/picomatch@2.3.1:
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
engines: {node: '>=8.6'}
dev: true
/resolve-pkg-maps@1.0.0:
resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==}
dev: true
/strip-json-comments@3.1.1:
resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==}
engines: {node: '>=8'}
dev: true
/to-fast-properties@3.0.1:
resolution: {integrity: sha512-/wtNi1tW1F3nf0OL6AqVxGw9Tr1ET70InMhJuVxPwFdGqparF0nQ4UWGLf2DsoI2bFDtthlBnALncZpUzOnsUw==}
engines: {node: '>=8'}
dev: false
/to-regex-range@5.0.1:
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
engines: {node: '>=8.0'}
dependencies:
is-number: 7.0.0
dev: true
/typescript@5.1.6:
resolution: {integrity: sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==}
engines: {node: '>=14.17'}
hasBin: true
dev: true
/uuid@8.3.2:
resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
hasBin: true
dev: false

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,5 +1,22 @@
import type {Dependencies, Signature} from '../interfaces/type.js'
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>
}
export const square =
<T>(dep: Dependencies<'multiply', T>): Signature<'square', T> =>
z => dep.multiply(z, z)
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']>()))

View File

@ -1,6 +1,27 @@
import {Dispatcher} from './core/Dispatcher.js'
import {
typeOf, ReflectionFunction, ReflectionClass, ReflectionKind, stringifyType,
ReceiveType, resolveReceiveType
} from '@deepkit/type'
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'
@ -9,6 +30,38 @@ import {absquare as absquare_complex} from './Complex/arithmetic.js'
const mockRealAdd = (a: number, b: number) => a+b
const mockComplexAbsquare = (z: Complex<number>) => z.re*z.re + z.im*z.im
const addRefl = ReflectionFunction.from(mockRealAdd)
console.log('----> I figured out:', addRefl, addRefl.getParameterNames(), addRefl.getParameterType('b'))
function bungle(deps: {
factor: (i: number) => number,
label: string
}) {
return (a: number) => deps.label + (deps.factor(2)*a)
}
let fn = (i:number) => 3*i
console.log("\nBungling", bungle({factor: fn, label:'hextupled: '})(7))
const bRefl = ReflectionFunction.from(bungle)
const depstype = bRefl.getParameterType('deps')
console.log('Deps type is', depstype)
console.log(' aka ', stringifyType(depstype))
if (depstype.kind == ReflectionKind.objectLiteral) {
const depsRefl = new ReflectionClass(depstype)
console.log(' With methods', depsRefl.getMethodNames())
const factorRefl = depsRefl.getMethod('factor')
console.log(' And factor method takes parameters',
factorRefl.getParameterNames())
const itype = factorRefl.getParameterType('i')
console.log(' Parameter `i` has type', itype)
console.log(' aka', stringifyType(itype))
} else {
console.log(' Not understanding deps')
}
const quatAbsquare = absquare_complex({
add: mockRealAdd,
absquare: mockComplexAbsquare

10
src/local.ts Normal file
View File

@ -0,0 +1,10 @@
import type {ImportedInterface} from './remote.js'
interface LocalInterface {
item: (a: number) => string
}
import {stringifyType, typeOf} from '@deepkit/type'
console.log('Locally:', stringifyType(typeOf<LocalInterface['item']>()))
console.log('Remotely:', stringifyType(typeOf<ImportedInterface['item']>()))

3
src/remote.ts Normal file
View File

@ -0,0 +1,3 @@
export interface ImportedInterface {
item: (a: number) => string
}

View File

@ -2,6 +2,8 @@
"compilerOptions": {
"target": "ES2022",
"rootDir": "./src",
"outDir": "./obj"
}
"outDir": "./obj",
"moduleResolution": "nodenext"
},
"reflection": true
}