mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 07:47:04 +00:00
Merge pull request #31089 from pawkrol/master
Add import function to MathJS types
This commit is contained in:
Vendored
+28
@@ -3,6 +3,7 @@
|
||||
// Definitions by: Ilya Shestakov <https://github.com/siavol>,
|
||||
// Andy Patterson <https://github.com/andnp>,
|
||||
// Brad Besserman <https://github.com/bradbesserman>
|
||||
// Pawel Krol <https://github.com/pawkrol>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
@@ -2571,6 +2572,23 @@ declare namespace math {
|
||||
* ‘string’, ‘Array’, ‘Date’.
|
||||
*/
|
||||
typeof(x: any): string;
|
||||
|
||||
/**
|
||||
* Import functions from an object or a module
|
||||
* To avoid errors when using one of the imported functions extend module like this:
|
||||
*
|
||||
* @example
|
||||
* // imported_math_functions.ts
|
||||
* declare module 'mathjs' {
|
||||
* interface MathJsStatic {
|
||||
* hello(a: number): number;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @param object An object with functions to be imported.
|
||||
* @param options An object with import options.
|
||||
*/
|
||||
import(object: ImportObject | ImportObject[], options: ImportOptions): void;
|
||||
}
|
||||
|
||||
interface Matrix {
|
||||
@@ -4542,4 +4560,14 @@ declare namespace math {
|
||||
*/
|
||||
typeof(): MathJsChain;
|
||||
}
|
||||
|
||||
interface ImportOptions {
|
||||
override?: boolean;
|
||||
silent?: boolean;
|
||||
wrap?: boolean;
|
||||
}
|
||||
|
||||
interface ImportObject {
|
||||
[key: string]: any;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Import needed for mathjs.import functionality (declaring/extending module)
|
||||
import * as math from 'mathjs';
|
||||
|
||||
/*
|
||||
Basic usage examples
|
||||
*/
|
||||
@@ -392,3 +395,27 @@ JSON serialization/deserialization
|
||||
const parsed = JSON.parse(stringified, math.json.reviver);
|
||||
parsed.bigNumber === math.bignumber('1.5'); // true
|
||||
}
|
||||
|
||||
/*
|
||||
Extend functionality with import
|
||||
*/
|
||||
|
||||
declare module 'mathjs' {
|
||||
interface MathJsStatic {
|
||||
testFun(): number;
|
||||
value: number;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const testFun = () => 5;
|
||||
|
||||
math.import({
|
||||
testFun,
|
||||
value: 10
|
||||
}, {});
|
||||
|
||||
math.testFun();
|
||||
|
||||
const a = math.value * 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user