feat: Try two different kinds of type reflection (#5)
Co-authored-by: Jos de Jong <wjosdejong@gmail.com> Reviewed-on: #5 Co-authored-by: Glen Whitney <glen@studioinfinity.org> Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
parent
239215c234
commit
59c325ff6c
7 changed files with 618 additions and 14 deletions
|
@ -17,7 +17,8 @@ export const Complex_type = {
|
|||
(z: Complex<unknown>) => joinTypes(dep.typeOf(z.re), dep.typeOf(z.im)),
|
||||
from: {
|
||||
Complex: <U,T>(dep: {convert: CommonSignature<U,T>['convert']}) =>
|
||||
(z: Complex<U>) => ({re: dep.convert(z.re), im: dep.convert(z.im)}),
|
||||
(z: Complex<U>): Complex<T> =>
|
||||
({re: dep.convert(z.re), im: dep.convert(z.im)}),
|
||||
T: <T>(dep: {zero: CommonSignature<T>['zero']}) =>
|
||||
(t: T) => ({re: t, im: dep.zero(t)})
|
||||
}
|
||||
|
|
|
@ -102,6 +102,10 @@ type Implementations<
|
|||
Specs extends Specifications<Signatures, NeedKeys, NeedList>
|
||||
> = {[K in NeedKeys]: ImpType<Signatures, K, Specs[K]>}
|
||||
|
||||
export interface ReflectedTypeInfo {
|
||||
reflectedType5: string
|
||||
}
|
||||
|
||||
// The builder interface that lets us assemble narrowly-typed Implementations:
|
||||
interface ImplementationBuilder<
|
||||
Signatures extends GenSigs,
|
||||
|
@ -135,7 +139,7 @@ interface ImplementationBuilder<
|
|||
Specs & {[K in NewKeys]: DepCheck<RD, Signatures>}
|
||||
>
|
||||
|
||||
ship(): Implementations<Signatures, NeedKeys, NeedList, Specs>
|
||||
ship(info?: ReflectedTypeInfo): Implementations<Signatures, NeedKeys, NeedList, Specs> & ReflectedTypeInfo
|
||||
}
|
||||
|
||||
// And a function that actually provides the builder interface:
|
||||
|
@ -187,9 +191,8 @@ function impBuilder<
|
|||
Specs & {[K in NewKeys]: DepCheck<RD, Signatures, DepKeys>}
|
||||
>
|
||||
},
|
||||
ship() {
|
||||
return (sofar as
|
||||
Implementations<Signatures, NeedKeys, NeedList, Specs>)
|
||||
ship(info?: ReflectedTypeInfo) {
|
||||
return { ...sofar, ...info }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@ import {inspect} from 'node:util'
|
|||
|
||||
import * as specifications from './all'
|
||||
|
||||
console.log(inspect(specifications, {depth: 8, colors: true}))
|
||||
console.log(inspect(specifications, {depth: 18, colors: true}))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue