33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
export interface AssociatedTypes<T> {
|
|
undefined: {
|
|
type: undefined
|
|
zero: undefined
|
|
one: undefined
|
|
nan: undefined
|
|
real: undefined
|
|
}
|
|
}
|
|
|
|
type AssociatedTypeNames = keyof AssociatedTypes<unknown>['undefined']
|
|
export type Lookup<T, Name extends AssociatedTypeNames> = {
|
|
[K in keyof AssociatedTypes<T>]:
|
|
T extends AssociatedTypes<T>[K]['type'] ? AssociatedTypes<T>[K][Name] : never
|
|
}[keyof AssociatedTypes<T>]
|
|
|
|
export type ZeroType<T> = Lookup<T, 'zero'>
|
|
export type OneType<T> = Lookup<T, 'one'>
|
|
export type WithConstants<T> = T | ZeroType<T> | OneType<T>
|
|
export type NaNType<T> = Lookup<T, 'nan'>
|
|
export type RealType<T> = Lookup<T, 'real'>
|
|
|
|
export type ZeroOp<T> = {op?: 'zero', (a: WithConstants<T>): ZeroType<T>}
|
|
export type OneOp<T> = {op?: 'one', (a: WithConstants<T>): OneType<T>}
|
|
export type NanOp<T> = {op?: 'nan', (a: T|NaNType<T>): NaNType<T>}
|
|
export type ReOp<T> = {op?: 're', (a: T): RealType<T>}
|
|
|
|
type NamedFunction = {op?: string, (...params: any[]): any}
|
|
export type Depends<FuncType extends NamedFunction> =
|
|
{[K in FuncType['op']]: FuncType}
|
|
|
|
|