fix #2603: added type definition for onUndefinedSymbol & onUndefinedFunction (#2610)

* 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:
BOUYA Med. Salim 2022-10-18 09:42:50 +01:00 committed by GitHub
parent f891381979
commit c6883db0d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

4
types/index.d.ts vendored
View File

@ -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
}
/**

View File

@ -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
*/