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

Add typechecking to itemsExpression #3610

Closed

Conversation

CharString
Copy link
Contributor

@CharString CharString commented Nov 14, 2023

Closes #3596

@CharString CharString linked an issue Nov 14, 2023 that may be closed by this pull request
4 tasks
@CharString CharString changed the title 3596 add typechecking to keuzeopties expressie Add typechecking to itemsExpression Nov 14, 2023
@CharString CharString marked this pull request as draft November 14, 2023 18:42
Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (36e7691) 95.97% compared to head (3986a89) 95.97%.
Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3610   +/-   ##
=======================================
  Coverage   95.97%   95.97%           
=======================================
  Files         680      680           
  Lines       21890    21891    +1     
  Branches     2532     2532           
=======================================
+ Hits        21008    21009    +1     
  Misses        611      611           
  Partials      271      271           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

package.json Outdated Show resolved Hide resolved
@CharString CharString force-pushed the 3596-add-typechecking-to-keuzeopties-expressie branch from 300398a to 001c6a5 Compare November 16, 2023 10:25
Forces expressions of type `string[][]`.

Accepting `[value: any, label: string][]` would require
open-formulieren/InferNoLogic#5

To allow

```ts
type Item = [value: any, label: string] | {value: any, label: string}
type ValidItemExpression = Item[]
```

open-formulieren/InferNoLogic#6 and even a union type!
@CharString CharString force-pushed the 3596-add-typechecking-to-keuzeopties-expressie branch from 001c6a5 to 3986a89 Compare November 16, 2023 10:30
@CharString CharString marked this pull request as ready for review November 16, 2023 11:01
Comment on lines +32 to +33
const result = infer({'===': [logic, expected]}, {});
return result.startsWith('result type:') || result;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infer API must change. This is ugly. Want to have more info from other tickets before making a decision and releasing a new npm package.

await expect(page.locator("css=.formio-dialog-content")).to_be_visible()
await expect(
page.locator('css=[data-component-key="openForms.itemsExpression"]')
).to_contain_text("Error")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contents of "Error" will change. These assertions just assert that type check has occurred and accepts correct expressions.
Testing for the better error messages belongs in a unittest, E2E is way to slow and expensive for that.

@SilviaAmAm SilviaAmAm requested review from sergei-maertens and SilviaAmAm and removed request for sergei-maertens November 17, 2023 15:00
Comment on lines +2130 to +2132
await editor.type(
'{"map": [{"var": "somevar"}, [{"var": ""}, {"cat": ["Optie ", {"var": ""}]}]]}'
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it know that {"var": ""} in the context of {"var": "somevar"} (is this checked that it is of type array?) is a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the exact order, but it follows from

  • {"cat": ["Optie ", {"var": ""}]}
  • the list of options is of string[][] / list[list[str]], therefore the result of the "map" is also of that type.

It's why the validateLogic passed the expression into

const result = infer({'===': [logic, expected]}, {});

with expected = [["", ""]] and logic = (in this case) the "map"

It uses the fact that "===" is a Callable[[T, T], boolean], so the parse of the result from the infer call is a lot easier. infer({"===": [{"var": "a"}, {"var": "b"}]}) does not imply that a and b have the same value, just the same type.

infer shouldn't return a string, of course, but before changing it, I like to have more use cases.

@sergei-maertens sergei-maertens marked this pull request as draft November 22, 2023 15:12
@sergei-maertens
Copy link
Member

Converted it back to draft so we don't get distracted by this PR - if I understood it correctly from the daily, the work is now happening in https://github.com/open-formulieren/formio-builder

@CharString CharString closed this Dec 6, 2023
@sergei-maertens sergei-maertens deleted the 3596-add-typechecking-to-keuzeopties-expressie branch June 17, 2024 13:00
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.

Add typechecking to keuzeopties expressie
3 participants