feat: TypeScript typings for Dispatcher implementations
A first pass at specifying some implementations in TypeScript that actually compiles. It doesn't do anything, as installing types and operation specifications are currently dummy operations, but they are all invoked.
This commit is contained in:
parent
2a9039ac67
commit
ccc6153786
14 changed files with 100 additions and 123 deletions
1
src/Complex/all.ts
Normal file
1
src/Complex/all.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * as Complex from './native.js'
|
1
src/Complex/native.ts
Normal file
1
src/Complex/native.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './type.js'
|
30
src/Complex/type.ts
Normal file
30
src/Complex/type.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
/// <reference path="../numbers/type.ts">
|
||||
import {joinTypes, typeOfDependency, Dependency} from '../core/Dispatcher.js'
|
||||
|
||||
export type Complex<T> = {re: T; im: T;}
|
||||
|
||||
export const Complex_type = {
|
||||
test: <T>(dep: {testT: (z: unknown) => z is T}) =>
|
||||
(z: unknown): z is Complex<T> =>
|
||||
typeof z === 'object' && 're' in z && 'im' in z
|
||||
&& dep.testT(z.re) && dep.testT(z.im),
|
||||
infer: (dep: typeOfDependency) =>
|
||||
(z: Complex<unknown>) => joinTypes(dep.typeOf(z.re), dep.typeOf(z.im)),
|
||||
from: {
|
||||
T: <T>(dep: Dependency<'zero', [T]>) => (t: T) =>
|
||||
({re: t, im: dep.zero(t)}),
|
||||
Complex: <U,T>(dep: {convert: (from: U) => T}) =>
|
||||
(z: Complex<U>) => ({re: dep.convert(z.re), im: dep.convert(z.im)})
|
||||
}
|
||||
}
|
||||
|
||||
export const complex_1 = <T>(dep: Dependency<'zero', [T]>) =>
|
||||
(t: T) => ({re: t, im: dep.zero(t)})
|
||||
export const complex_2 = <T>(t: T, u: T) => ({re: t, im: u})
|
||||
|
||||
declare module "../core/Dispatcher" {
|
||||
interface ImplementationTypes {
|
||||
complex_1_Complex: typeof complex_1
|
||||
complex_2_Complex: typeof complex_2
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue