WIP: try to use ts-macros for more implementations

This commit is contained in:
Glen Whitney 2023-09-18 10:14:11 -07:00
parent dc6cf5165d
commit 0e2a1e830a
7 changed files with 30 additions and 111 deletions

View file

@ -1,3 +1,5 @@
import {$$typeToString, $$ident, $$define} from 'ts-macros'
/*****
* Every typocomath type has some associated types; they need
* to be published in the following interface. The key is the
@ -74,6 +76,13 @@ type SignatureKey<T> = keyof Signatures<T>
export type Signature<Name extends SignatureKey<T>, T> = Signatures<T>[Name]
export type Returns<Name extends SignatureKey<T>, T> = ReturnType<Signatures<T>[Name]>
export type Dependencies<Name extends SignatureKey<T>, T> = {[K in Name]: Signature<K, T>}
type Deps<T> = T extends unknown ? { [K in keyof T]: T[K] } : never;
export type Dependencies<Name extends SignatureKey<T>, T> = Deps<{[K in Name]: Signature<K, T>}>
export type AliasOf<Name extends string, T> = T & {aliasOf?: Name}
// For defining implementations with type reflection
export function $implement<Impl>(name: string, expr: Impl) {
$$define!(name, expr, false, true); // Final `true` is export
$$ident!(name).reflectedType = $$typeToString!<Impl>();
}