fix(types): add ResultSet interface and improve isResultSet typing#3481
Conversation
josdejong
left a comment
There was a problem hiding this comment.
Thanks @ranidam for working out this PR!
I made three inline comments, can you have a look at those?
And can you fix the linting errors? You can automatically fix them by running npm run format, and you can check if there are linting issues by running npm run lint.
|
|
|
Thanks Rani, all good to go now 👌 |
|
Your fix is published now in |
|
Thanks so much, @josdejong! 🙌 |
This PR introduces proper TypeScript support for the
ResultSetreturned byevaluate()when executing multiple expressions in MathJS.Changes
ResultSetinterface totypes/index.d.tsisResultSettype guard to use a type predicate(x is ResultSet)test/typescript-tests/testTypes.tsto validate inferenceWhen using
evaluate()with multiple expressions (e.g.,1 + 1; 2 + 2;), MathJS returns aResultSet.However:
a) The
ResultSettype was not previously exportedb)
isResultSet()did not indicate that the input is aResultSetc) This caused issues when trying to type and handle
evaluate()results safelyThis PR fixes those gaps, allowing TypeScript developers to detect and type
ResultSetresults reliably.Let me know if you'd like me to adjust anything further!