Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evaluateExpression? #11

Open
tb2johm opened this issue Sep 6, 2022 · 3 comments
Open

evaluateExpression? #11

tb2johm opened this issue Sep 6, 2022 · 3 comments

Comments

@tb2johm
Copy link

tb2johm commented Sep 6, 2022

In the Readme.md under the heading Custom Language it's described how to evaluate an expression (with new ExpressionParser(arithmeticLanguage).evaluateExpression(expr)).

However I can't get this to work. Looking in the code I can't even see any evaluateExpression.

Have I misunderstood something, or is the documentation faulty?

@j4k0xb
Copy link

j4k0xb commented Sep 7, 2022

it's called expressionToValue, docs seem to be faulty

@andras-gyarmati
Copy link

yes it's expressionToValue, but then it complains about types are not explicitly written (Parameter 'a' implicitly has an 'any' type), and when I fix that it says that 'ExpressionThunk' is not assignable to type 'number'

@j4k0xb
Copy link

j4k0xb commented Dec 10, 2023

theres no way of specifying the thunk/term types
don't think you can do much about it other than cast, ts-ignore or runtime checks

const arithmeticLanguage: ExpressionParserOptions = {
  INFIX_OPS: {
    "+": function (a, b) {
      return (a() as number) + (b() as number);
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants