From 1b9d6b64287cdc4629a774ebee0367cfe7a90cc1 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Wed, 4 Jan 2023 12:28:24 +0100 Subject: [PATCH] chore: use direct function definitions instead of `{ params, returns }` --- src/Complex/arithmetic.ts | 4 ++-- src/Complex/type.ts | 2 +- src/interfaces/arithmetic.ts | 27 +++++++++++---------------- src/interfaces/predicate.ts | 7 ++++--- src/interfaces/relational.ts | 6 +++--- src/interfaces/type.ts | 13 ++++++------- 6 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/Complex/arithmetic.ts b/src/Complex/arithmetic.ts index e11d91e..cc3d49b 100644 --- a/src/Complex/arithmetic.ts +++ b/src/Complex/arithmetic.ts @@ -9,8 +9,8 @@ declare module "../interfaces/type" { // after removing any `_...` suffixes; the following should be // additional dispatches for add and divide, not separate // operations, in the final mathjs bundle. - add_real: {params: [T, RealType], returns: T} - divide_real: {params: [T, RealType], returns: T} + add_real: (a: T, b: RealType) => T + divide_real: (a: T, b: RealType) => T } } diff --git a/src/Complex/type.ts b/src/Complex/type.ts index 43c79fe..50a1314 100644 --- a/src/Complex/type.ts +++ b/src/Complex/type.ts @@ -32,7 +32,7 @@ declare module "../interfaces/type" { } interface Signatures { - complex: {params: [T] | [T,T], returns: Complex} + complex: ((re: T) => Complex) | ((re: T, im: T) => Complex) } } diff --git a/src/interfaces/arithmetic.ts b/src/interfaces/arithmetic.ts index f77ceb1..df2d765 100644 --- a/src/interfaces/arithmetic.ts +++ b/src/interfaces/arithmetic.ts @@ -1,23 +1,18 @@ import type {Complex} from '../Complex/type.js' import type {RealType} from './type.js' -type UnaryOperator = {params: [T], returns: T} -type BinaryOperator = {params: [T, T], returns: T} declare module "./type" { interface Signatures { - add: BinaryOperator - unaryMinus: UnaryOperator - conj: UnaryOperator - subtract: BinaryOperator - multiply: BinaryOperator - square: UnaryOperator - absquare: {params: [T], returns: RealType} - reciprocal: UnaryOperator - divide: BinaryOperator - conservativeSqrt: UnaryOperator - sqrt: { - params: [T], - returns: T extends Complex ? T : T | Complex - } + add: (a: T, b: T) => T + unaryMinus: (a: T) => T + conj: (a: T) => T + subtract: (a: T, b: T) => T + multiply: (a: T, b: T) => T + square: (a: T) => T + absquare: (a: T) => RealType + reciprocal: (a: T) => T + divide: (a: T, b: T) => T + conservativeSqrt: (a: T) => T + sqrt: (a: T)=> T extends Complex ? T : T | Complex } } diff --git a/src/interfaces/predicate.ts b/src/interfaces/predicate.ts index b4c7393..93d3b4a 100644 --- a/src/interfaces/predicate.ts +++ b/src/interfaces/predicate.ts @@ -1,9 +1,10 @@ // Warning: a module must have something besides just a "declare module" // section; otherwise it is ignored. -export type UnaryPredicate = {params: [T], returns: boolean} +export type UnaryPredicate = (a: T) => boolean + declare module "./type" { interface Signatures { - isReal: UnaryPredicate - isSquare: UnaryPredicate + isReal: (a: T) => boolean + isSquare: (a: T) => boolean } } diff --git a/src/interfaces/relational.ts b/src/interfaces/relational.ts index 9b511b0..e2aa3a1 100644 --- a/src/interfaces/relational.ts +++ b/src/interfaces/relational.ts @@ -1,9 +1,9 @@ // Warning: a module must have something besides just a "declare module" // section; otherwise it is ignored. -export type BinaryPredicate = {params: [T, T], returns: boolean} +export type BinaryPredicate = (a: T, b: T) => T declare module "./type" { interface Signatures { - equal: BinaryPredicate - unequal: BinaryPredicate + equal: (a: T, b: T) => boolean + unequal: (a: T, b: T) => boolean } } diff --git a/src/interfaces/type.ts b/src/interfaces/type.ts index 4596d7f..c68c98a 100644 --- a/src/interfaces/type.ts +++ b/src/interfaces/type.ts @@ -58,17 +58,16 @@ export type RealType = ALookup * key 're' in the interface. ****/ export interface Signatures { - zero: {params: [T], returns: ZeroType} - one: {params: [T], returns: OneType} + zero: (a: T) => ZeroType + one: (a: T) => OneType // nan needs to be able to operate on its own output for everything // else to compile. That's why its parameter type is widened: - nan: {params: [T | NaNType], returns: NaNType} - re: {params: [T], returns: RealType} + nan: (a: T | NaNType) => NaNType + re: (a: T) => RealType } type SignatureKey = keyof Signatures -export type Returns = Signatures[Name]['returns'] -export type Signature = - (...args: Signatures[Name]['params']) => Returns +export type Signature = Signatures[Name] +export type Returns = ReturnType[Name]> export type Dependencies = {[K in Name]: Signature}