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

Update type definitions #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jesse-r-s-hines
Copy link

@jesse-r-s-hines jesse-r-s-hines commented Nov 12, 2021

Minor changes to make the type definitions more accurate

Add operators.array to ParserOptions

Add types for Parser.unaryOps, Parser.functions, and Parser.consts

Add boolean and array to Value type, since evaluate can return those.

Parser.evaluate("true") // returns boolean
Parser.evaluate("[1,2,3]") // returns array

Make function Values take any[] instead of Value[]. TypeScript won't let you assign a function that only takes number/string etc. to (...args: Value[]) => Value, so make it take any.

let x: (...args: Value[]) => Value = Math.max // TypeScript will error
let x: (...args: any[]) => Value = Math.max // TypeScript is happy

Update evaluate's and simplify's definition to only take an object of Values instead of a Value (which can also be array/boolean/etc.)

Update evaluate functions to return a Value type instead of just number

@jesse-r-s-hines jesse-r-s-hines force-pushed the update-type-definitions branch 2 times, most recently from 5282c73 to f5ff3e1 Compare November 13, 2021 16:00
Add `operators.array` to `ParserOptions`

Add types for `Parser.unaryOps`, `Parser.functions`, and `Parser.consts`

Add boolean and array to `Value` type, since `evaluate` can return those.
```ts
Parser.evaluate("true") // returns boolean
Parser.evaluate("[1,2,3]") // returns array
```

Make function `Value`s take `any[]` instead of `Value[]`. TypeScript
won't let you assign a function that only takes `number`/`string` etc.
to `(...args: Value[]) => Value`, so make it take any.
```ts
let x: (...args: Value[]) => Value = Math.max // TypeScript will error
let x: (...args: any[]) => Value = Math.max // TypeScript is happy
```

Update `evaluate`'s and `simplify`'s definition to only take an object
of `Value`s instead of a `Value` (which can also be array/boolean/etc.)

Update `evaluate` functions to return a `Value` type instead of just
`number`
@alecmev
Copy link

alecmev commented Mar 29, 2023

It's better to move these to DefinitelyTyped, until expr-eval is rewritten in TypeScript. More info.

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

Successfully merging this pull request may close these issues.

2 participants