File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ import {
48
48
SLUDecomposition ,
49
49
SymbolNode ,
50
50
Unit ,
51
+ evaluate ,
52
+ isResultSet ,
51
53
UnitPrefix
52
54
} from 'mathjs'
53
55
@@ -171,6 +173,12 @@ Bignumbers examples
171
173
)
172
174
}
173
175
}
176
+ const result = evaluate ( '1 + 1; 2 + 2;' ) // multi-expression input
177
+
178
+ if ( isResultSet ( result ) ) {
179
+ const entries = result . valueOf ( ) // ✅ should be typed as unknown[]
180
+ const _last = entries . slice ( - 1 ) [ 0 ] // ✅ access last result safely
181
+ }
174
182
175
183
/*
176
184
Arithmetic function examples
Original file line number Diff line number Diff line change @@ -3518,7 +3518,7 @@ export interface MathJsInstance extends MathJsFactory {
3518
3518
3519
3519
isBoolean ( x : unknown ) : x is boolean
3520
3520
3521
- isResultSet ( x : unknown ) : boolean
3521
+ isResultSet ( x : unknown ) : x is ResultSet
3522
3522
3523
3523
isHelp ( x : unknown ) : x is Help
3524
3524
@@ -4319,6 +4319,14 @@ export interface EvalFunction {
4319
4319
evaluate ( scope ?: any ) : any
4320
4320
}
4321
4321
4322
+ // ResultSet type and helper
4323
+ export interface ResultSet {
4324
+ entries : unknown [ ]
4325
+ valueOf ( ) : unknown [ ]
4326
+ toString ( ) : string
4327
+ toJSON ( ) : MathJSON
4328
+ }
4329
+
4322
4330
export interface MathNode {
4323
4331
isNode : true
4324
4332
comment : string
You can’t perform that action at this time.
0 commit comments