chore: use direct function definitions instead of { params, returns }
This commit is contained in:
parent
a0b21181e6
commit
1b9d6b6428
@ -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<T>], returns: T}
|
||||
divide_real: {params: [T, RealType<T>], returns: T}
|
||||
add_real: (a: T, b: RealType<T>) => T
|
||||
divide_real: (a: T, b: RealType<T>) => T
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ declare module "../interfaces/type" {
|
||||
}
|
||||
|
||||
interface Signatures<T> {
|
||||
complex: {params: [T] | [T,T], returns: Complex<T>}
|
||||
complex: ((re: T) => Complex<T>) | ((re: T, im: T) => Complex<T>)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,18 @@
|
||||
import type {Complex} from '../Complex/type.js'
|
||||
import type {RealType} from './type.js'
|
||||
|
||||
type UnaryOperator<T> = {params: [T], returns: T}
|
||||
type BinaryOperator<T> = {params: [T, T], returns: T}
|
||||
declare module "./type" {
|
||||
interface Signatures<T> {
|
||||
add: BinaryOperator<T>
|
||||
unaryMinus: UnaryOperator<T>
|
||||
conj: UnaryOperator<T>
|
||||
subtract: BinaryOperator<T>
|
||||
multiply: BinaryOperator<T>
|
||||
square: UnaryOperator<T>
|
||||
absquare: {params: [T], returns: RealType<T>}
|
||||
reciprocal: UnaryOperator<T>
|
||||
divide: BinaryOperator<T>
|
||||
conservativeSqrt: UnaryOperator<T>
|
||||
sqrt: {
|
||||
params: [T],
|
||||
returns: T extends Complex<any> ? T : T | Complex<T>
|
||||
}
|
||||
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<T>
|
||||
reciprocal: (a: T) => T
|
||||
divide: (a: T, b: T) => T
|
||||
conservativeSqrt: (a: T) => T
|
||||
sqrt: (a: T)=> T extends Complex<unknown> ? T : T | Complex<T>
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
// Warning: a module must have something besides just a "declare module"
|
||||
// section; otherwise it is ignored.
|
||||
export type UnaryPredicate<T> = {params: [T], returns: boolean}
|
||||
export type UnaryPredicate<T> = (a: T) => boolean
|
||||
|
||||
declare module "./type" {
|
||||
interface Signatures<T> {
|
||||
isReal: UnaryPredicate<T>
|
||||
isSquare: UnaryPredicate<T>
|
||||
isReal: (a: T) => boolean
|
||||
isSquare: (a: T) => boolean
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
// Warning: a module must have something besides just a "declare module"
|
||||
// section; otherwise it is ignored.
|
||||
export type BinaryPredicate<T> = {params: [T, T], returns: boolean}
|
||||
export type BinaryPredicate<T> = (a: T, b: T) => T
|
||||
declare module "./type" {
|
||||
interface Signatures<T> {
|
||||
equal: BinaryPredicate<T>
|
||||
unequal: BinaryPredicate<T>
|
||||
equal: (a: T, b: T) => boolean
|
||||
unequal: (a: T, b: T) => boolean
|
||||
}
|
||||
}
|
||||
|
@ -58,17 +58,16 @@ export type RealType<T> = ALookup<T, 'real'>
|
||||
* key 're' in the interface.
|
||||
****/
|
||||
export interface Signatures<T> {
|
||||
zero: {params: [T], returns: ZeroType<T>}
|
||||
one: {params: [T], returns: OneType<T>}
|
||||
zero: (a: T) => ZeroType<T>
|
||||
one: (a: T) => OneType<T>
|
||||
// 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<T>], returns: NaNType<T>}
|
||||
re: {params: [T], returns: RealType<T>}
|
||||
nan: (a: T | NaNType<T>) => NaNType<T>
|
||||
re: (a: T) => RealType<T>
|
||||
}
|
||||
|
||||
type SignatureKey = keyof Signatures<unknown>
|
||||
|
||||
export type Returns<Name extends SignatureKey, T> = Signatures<T>[Name]['returns']
|
||||
export type Signature<Name extends SignatureKey, T> =
|
||||
(...args: Signatures<T>[Name]['params']) => Returns<Name, T>
|
||||
export type Signature<Name extends SignatureKey, T> = Signatures<T>[Name]
|
||||
export type Returns<Name extends SignatureKey, T> = ReturnType<Signatures<T>[Name]>
|
||||
export type Dependencies<Name extends SignatureKey, T> = {[K in Name]: Signature<K, T>}
|
||||
|
Loading…
Reference in New Issue
Block a user