mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
* fix #2603: added type definition for SymbolNode.onUndefinedSymbol and FuctionNode.onUndefinedFunction * fix return type of onUndefinedFunction * fix return type of onUndefinedFunction * fix onUndefinedSymbol & onUndefinedFunction types, added examples * update onUndefinedFunction ts example
This commit is contained in:
parent
f891381979
commit
c6883db0d3
4
types/index.d.ts
vendored
4
types/index.d.ts
vendored
@ -258,6 +258,8 @@ declare namespace math {
|
||||
}
|
||||
interface FunctionNodeCtor {
|
||||
new (fn: MathNode | string, args: MathNode[]): FunctionNode
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
onUndefinedFunction: (name: string) => any
|
||||
}
|
||||
|
||||
interface IndexNode extends MathNode {
|
||||
@ -383,6 +385,8 @@ declare namespace math {
|
||||
}
|
||||
interface SymbolNodeCtor {
|
||||
new (name: string): SymbolNode
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
onUndefinedSymbol: (name: string) => any
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1488,6 +1488,19 @@ Units examples
|
||||
math.unit('1 m').splitUnit(['ft', 'in'])
|
||||
}
|
||||
|
||||
/**
|
||||
* Example of custom fallback for onUndefinedSymbol & onUndefinedFunction
|
||||
*/
|
||||
{
|
||||
const math = create(all, {})
|
||||
|
||||
math.SymbolNode.onUndefinedSymbol = () => null
|
||||
|
||||
assert.strictEqual(math.evaluate('nonExistingSymbol'), null)
|
||||
|
||||
math.FunctionNode.onUndefinedFunction = () => () => 42
|
||||
}
|
||||
|
||||
/*
|
||||
Expression tree examples
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user