silentmatt / expr-eval

Mathematical expression evaluator in JavaScript
http://silentmatt.com/javascript-expression-evaluator/
MIT License
1.21k stars 239 forks source link

fix incorrect return types #263

Closed trusktr closed 3 years ago

trusktr commented 3 years ago

This is what I see at runtime:

const formulaResult = Parser.evaluate(this.durationFormula, formulaInputs)
console.log('typeof result:', typeof formulaResult) // string

The return of evaluate was number, but I see strings being returned.

Why was Expression#evaluate's return type any? Does it return things other than strings?

trusktr commented 3 years ago

Oh wait, I see my formula is passing in a single input that is a string. Maybe that's why...

trusktr commented 3 years ago

Yeah, that was it, my formula only had one input (equivalent to 1 * x, but looks like it simply return the value back). 😆