-
Notifications
You must be signed in to change notification settings - Fork 357
Add tests to ensure Perseus JSON parsers are idempotent #2403
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
Conversation
Size Change: +14 B (0%) Total Size: 466 kB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (d36f830) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR2403 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.js -t PR2403 |
1f59a66
to
e710c9c
Compare
7cf70d6
to
bcb6197
Compare
parser: Parser<T>, | ||
fallback: (missingValue: null | undefined) => Default, | ||
): Parser<T | Default> { | ||
fallback: (missingValue: null | undefined) => NoInfer<T>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about NoInfer<T>
(I read https://www.totaltypescript.com/noinfer).
So this blocks the fallback's return value from being included in the type inference for T
, right? So the return value's T
will be only inferred from the parser
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct! FWIW writing this code made me happy because I think it's a perfect place to use NoInfer
.
import {defaulted} from "../general-purpose-parsers/defaulted"; | ||
|
||
import {parseImages} from "./images-map"; | ||
import {parseWidgetsMap} from "./widgets-map"; | ||
|
||
export const parseHint = object({ | ||
replace: defaulted(boolean, () => undefined), | ||
replace: defaulted(optional(boolean), () => undefined), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear why you needed to wrap optional()
here? Is it because the replace
can be undefined
and if we didn't wrap it in optional()
here, we'd have a resulting type of boolean
because the fallback is ignored for type inference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
// once is the same as running it many times. Idempotency is | ||
// valuable because it means e.g. that if we run the parser on data | ||
// before saving it to datastore, it won't be changed by being |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 💯
…nsure Perseus JSON parsers are idempotent
bcb6197
to
d36f830
Compare
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @khanacademy/[email protected] ### Major Changes - [#2402](#2402) [`558cc1cc6`](558cc1c) Thanks [@benchristel](https://github.com/benchristel)! - Add typetests to ensure that the data format accepted by `parseAndMigratePerseusItem` stays in sync with the types in `data-schema.ts`, exported from `@khanacademy/perseus-core`. Breaking change: `PerseusGraphTypeAngle.coords` can no longer be `null`; use `undefined` instead. - [#2436](#2436) [`79a84d31b`](79a84d3) Thanks [@benchristel](https://github.com/benchristel)! - Change the type of `PerseusNumberLineWidgetOptions.correctRel` to `"eq" | "lt" | "gt" | "le" | "ge"`, to better reflect our data and the semantics of this field. - [#2425](#2425) [`4282de2b2`](4282de2) Thanks [@benchristel](https://github.com/benchristel)! - Add `isInequality` to the `PerseusNumberLineWidgetOptions` type. The NumberLine component was using this field, but it wasn't represented in the types. - [#2417](#2417) [`4184314fe`](4184314) Thanks [@handeyeco](https://github.com/handeyeco)! - Enable Group to be rendered/answered with answerless item data - [#2380](#2380) [`1f88cc191`](1f88cc1) Thanks [@benchristel](https://github.com/benchristel)! - Removes `undefined` from the types of `PerseusInteractiveGraphWidgetOptions.lockedFigures` and the `labels` property of locked figures. Removes the `coords` property from interactive graph widget options types, for graphs that do not use it (all but the `point` graph type). This is a breaking change because assigning `undefined` to `lockedFigures` or `labels`, or setting `coord` in an object literal, will now give a type error. Callers should use an empty array instead of `undefined` for `lockedFigures` and `labels`. Avoid setting `coord` for graph types other than `point`. ### Minor Changes - [#2423](#2423) [`22e7de307`](22e7de3) Thanks [@Myranae](https://github.com/Myranae)! - Update Plotter widget to render with answerless data. Adds test and stories for answerless rendering. - [#2448](#2448) [`b7d3b9eaf`](b7d3b9e) Thanks [@tony-dinh](https://github.com/tony-dinh)! - Introduce `itemHasHints` & `itemHasRationales` methods to detect when a parsed PerseusItem contains widgets with hints or rationales, respectively. - [#2441](#2441) [`f1662239e`](f166223) Thanks [@Myranae](https://github.com/Myranae)! - Update Orderer widget to render with answerless data. Adds tests and stories for answerless rendering. - [#2387](#2387) [`aa7b1b621`](aa7b1b6) Thanks [@Myranae](https://github.com/Myranae)! - Update Matrix widget to render with answerless data. Adds tests and stories for answerless rendering. ### Patch Changes - [#2426](#2426) [`a2701f002`](a2701f0) Thanks [@handeyeco](https://github.com/handeyeco)! - Add tests/stories to prove InputNumber is interactive with answerless data - [#2446](#2446) [`ca4df1cf8`](ca4df1c) Thanks [@benchristel](https://github.com/benchristel)! - Internal: suppress immutable-data lint rule in a test - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2459](#2459) [`c27162249`](c271622) Thanks [@benchristel](https://github.com/benchristel)! - Internal: use 'require' instead of 'import' in test script so it will work on more platforms - [#2434](#2434) [`28c395f8e`](28c395f) Thanks [@benchristel](https://github.com/benchristel)! - Internal: add tests verifying that NumberLine widgets work with answerless data - [#2403](#2403) [`bfa5ce68a`](bfa5ce6) Thanks [@benchristel](https://github.com/benchristel)! - Internal: add tests to ensure Perseus JSON parsers are idempotent - [#2439](#2439) [`1b773e2a0`](1b773e2) Thanks [@benchristel](https://github.com/benchristel)! - The Perseus JSON parser now accepts cross-realm objects. - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values - Updated dependencies \[[`e7807485e`](e780748), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Minor Changes - [#2423](#2423) [`22e7de307`](22e7de3) Thanks [@Myranae](https://github.com/Myranae)! - Update Plotter widget to render with answerless data. Adds test and stories for answerless rendering. - [#2449](#2449) [`2243316be`](2243316) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Add option to ButtonGroup component to allow selected button to be styled - [#2441](#2441) [`f1662239e`](f166223) Thanks [@Myranae](https://github.com/Myranae)! - Update Orderer widget to render with answerless data. Adds tests and stories for answerless rendering. - [#2387](#2387) [`aa7b1b621`](aa7b1b6) Thanks [@Myranae](https://github.com/Myranae)! - Update Matrix widget to render with answerless data. Adds tests and stories for answerless rendering. ### Patch Changes - [#2426](#2426) [`a2701f002`](a2701f0) Thanks [@handeyeco](https://github.com/handeyeco)! - Add tests/stories to prove InputNumber is interactive with answerless data - [#2447](#2447) [`39ca81d0f`](39ca81d) Thanks [@handeyeco](https://github.com/handeyeco)! - Clean up a ServerItemRenderer test to make it more focused - [#2436](#2436) [`79a84d31b`](79a84d3) Thanks [@benchristel](https://github.com/benchristel)! - Change the type of `PerseusNumberLineWidgetOptions.correctRel` to `"eq" | "lt" | "gt" | "le" | "ge"`, to better reflect our data and the semantics of this field. - [#2425](#2425) [`4282de2b2`](4282de2) Thanks [@benchristel](https://github.com/benchristel)! - Add `isInequality` to the `PerseusNumberLineWidgetOptions` type. The NumberLine component was using this field, but it wasn't represented in the types. - [#2452](#2452) [`4b25852db`](4b25852) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix types used for forwardref in `expression` widget - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2417](#2417) [`4184314fe`](4184314) Thanks [@handeyeco](https://github.com/handeyeco)! - Enable Group to be rendered/answered with answerless item data - [#2380](#2380) [`1f88cc191`](1f88cc1) Thanks [@benchristel](https://github.com/benchristel)! - Removes `undefined` from the types of `PerseusInteractiveGraphWidgetOptions.lockedFigures` and the `labels` property of locked figures. Removes the `coords` property from interactive graph widget options types, for graphs that do not use it (all but the `point` graph type). This is a breaking change because assigning `undefined` to `lockedFigures` or `labels`, or setting `coord` in an object literal, will now give a type error. Callers should use an empty array instead of `undefined` for `lockedFigures` and `labels`. Avoid setting `coord` for graph types other than `point`. - [#2416](#2416) [`a90ebca08`](a90ebca) Thanks [@ivyolamit](https://github.com/ivyolamit)! - Update Radio Widget docs to include rationales in the test data - [#2434](#2434) [`28c395f8e`](28c395f) Thanks [@benchristel](https://github.com/benchristel)! - Internal: add tests verifying that NumberLine widgets work with answerless data - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values - Updated dependencies \[[`a2701f002`](a2701f0), [`558cc1cc6`](558cc1c), [`79a84d31b`](79a84d3), [`ca4df1cf8`](ca4df1c), [`4282de2b2`](4282de2), [`e7807485e`](e780748), [`4184314fe`](4184314), [`1f88cc191`](1f88cc1), [`22e7de307`](22e7de3), [`c27162249`](c271622), [`28c395f8e`](28c395f), [`bfa5ce68a`](bfa5ce6), [`b7d3b9eaf`](b7d3b9e), [`f1662239e`](f166223), [`aa7b1b621`](aa7b1b6), [`1b773e2a0`](1b773e2), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Minor Changes - [#2449](#2449) [`2243316be`](2243316) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - UI updates to Expression editor ### Patch Changes - [#2402](#2402) [`558cc1cc6`](558cc1c) Thanks [@benchristel](https://github.com/benchristel)! - Add typetests to ensure that the data format accepted by `parseAndMigratePerseusItem` stays in sync with the types in `data-schema.ts`, exported from `@khanacademy/perseus-core`. Breaking change: `PerseusGraphTypeAngle.coords` can no longer be `null`; use `undefined` instead. - [#2421](#2421) [`bedcfc6f2`](bedcfc6) Thanks [@mahtabsabet](https://github.com/mahtabsabet)! - Allow widgets within hints to be collapsed/expanded through editor controls - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2430](#2430) [`312166b0b`](312166b) Thanks [@jandrade](https://github.com/jandrade)! - Updates the `ExpressionEditor` widget to use a WB `Button` instance that resembles the previously supported `light` variant (now deprecated). - [#2417](#2417) [`4184314fe`](4184314) Thanks [@handeyeco](https://github.com/handeyeco)! - Enable Group to be rendered/answered with answerless item data - [#2380](#2380) [`1f88cc191`](1f88cc1) Thanks [@benchristel](https://github.com/benchristel)! - Removes `undefined` from the types of `PerseusInteractiveGraphWidgetOptions.lockedFigures` and the `labels` property of locked figures. Removes the `coords` property from interactive graph widget options types, for graphs that do not use it (all but the `point` graph type). This is a breaking change because assigning `undefined` to `lockedFigures` or `labels`, or setting `coord` in an object literal, will now give a type error. Callers should use an empty array instead of `undefined` for `lockedFigures` and `labels`. Avoid setting `coord` for graph types other than `point`. - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values - Updated dependencies \[[`a2701f002`](a2701f0), [`39ca81d0f`](39ca81d), [`558cc1cc6`](558cc1c), [`79a84d31b`](79a84d3), [`ca4df1cf8`](ca4df1c), [`4282de2b2`](4282de2), [`4b25852db`](4b25852), [`e7807485e`](e780748), [`4184314fe`](4184314), [`1f88cc191`](1f88cc1), [`22e7de307`](22e7de3), [`a90ebca08`](a90ebca), [`c27162249`](c271622), [`28c395f8e`](28c395f), [`2243316be`](2243316), [`bfa5ce68a`](bfa5ce6), [`b7d3b9eaf`](b7d3b9e), [`f1662239e`](f166223), [`aa7b1b621`](aa7b1b6), [`1b773e2a0`](1b773e2), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values - Updated dependencies \[[`e7807485e`](e780748), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - Updated dependencies \[[`a2701f002`](a2701f0), [`558cc1cc6`](558cc1c), [`79a84d31b`](79a84d3), [`ca4df1cf8`](ca4df1c), [`4282de2b2`](4282de2), [`e7807485e`](e780748), [`4184314fe`](4184314), [`1f88cc191`](1f88cc1), [`22e7de307`](22e7de3), [`c27162249`](c271622), [`28c395f8e`](28c395f), [`bfa5ce68a`](bfa5ce6), [`b7d3b9eaf`](b7d3b9e), [`f1662239e`](f166223), [`aa7b1b621`](aa7b1b6), [`1b773e2a0`](1b773e2), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values - Updated dependencies \[[`a2701f002`](a2701f0), [`558cc1cc6`](558cc1c), [`79a84d31b`](79a84d3), [`ca4df1cf8`](ca4df1c), [`4282de2b2`](4282de2), [`e7807485e`](e780748), [`4184314fe`](4184314), [`1f88cc191`](1f88cc1), [`22e7de307`](22e7de3), [`c27162249`](c271622), [`28c395f8e`](28c395f), [`bfa5ce68a`](bfa5ce6), [`b7d3b9eaf`](b7d3b9e), [`f1662239e`](f166223), [`aa7b1b621`](aa7b1b6), [`1b773e2a0`](1b773e2), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values - Updated dependencies \[[`a2701f002`](a2701f0), [`558cc1cc6`](558cc1c), [`79a84d31b`](79a84d3), [`ca4df1cf8`](ca4df1c), [`4282de2b2`](4282de2), [`e7807485e`](e780748), [`4184314fe`](4184314), [`1f88cc191`](1f88cc1), [`22e7de307`](22e7de3), [`c27162249`](c271622), [`28c395f8e`](28c395f), [`bfa5ce68a`](bfa5ce6), [`b7d3b9eaf`](b7d3b9e), [`f1662239e`](f166223), [`aa7b1b621`](aa7b1b6), [`1b773e2a0`](1b773e2), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values - Updated dependencies \[[`a2701f002`](a2701f0), [`558cc1cc6`](558cc1c), [`79a84d31b`](79a84d3), [`ca4df1cf8`](ca4df1c), [`4282de2b2`](4282de2), [`e7807485e`](e780748), [`4184314fe`](4184314), [`1f88cc191`](1f88cc1), [`22e7de307`](22e7de3), [`c27162249`](c271622), [`28c395f8e`](28c395f), [`bfa5ce68a`](bfa5ce6), [`b7d3b9eaf`](b7d3b9e), [`f1662239e`](f166223), [`aa7b1b621`](aa7b1b6), [`1b773e2a0`](1b773e2), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2417](#2417) [`4184314fe`](4184314) Thanks [@handeyeco](https://github.com/handeyeco)! - Enable Group to be rendered/answered with answerless item data - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values - Updated dependencies \[[`a2701f002`](a2701f0), [`558cc1cc6`](558cc1c), [`79a84d31b`](79a84d3), [`ca4df1cf8`](ca4df1c), [`4282de2b2`](4282de2), [`e7807485e`](e780748), [`4184314fe`](4184314), [`1f88cc191`](1f88cc1), [`22e7de307`](22e7de3), [`c27162249`](c271622), [`28c395f8e`](28c395f), [`bfa5ce68a`](bfa5ce6), [`b7d3b9eaf`](b7d3b9e), [`f1662239e`](f166223), [`aa7b1b621`](aa7b1b6), [`1b773e2a0`](1b773e2), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values ## @khanacademy/[email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - Updated dependencies \[[`e7807485e`](e780748), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values - Updated dependencies \[[`e7807485e`](e780748), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses - [#2438](#2438) [`3f32593c9`](3f32593) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add a linter to prevent accidental mutation of object and array values - Updated dependencies \[[`a2701f002`](a2701f0), [`558cc1cc6`](558cc1c), [`79a84d31b`](79a84d3), [`ca4df1cf8`](ca4df1c), [`4282de2b2`](4282de2), [`e7807485e`](e780748), [`4184314fe`](4184314), [`1f88cc191`](1f88cc1), [`22e7de307`](22e7de3), [`c27162249`](c271622), [`28c395f8e`](28c395f), [`bfa5ce68a`](bfa5ce6), [`b7d3b9eaf`](b7d3b9e), [`f1662239e`](f166223), [`aa7b1b621`](aa7b1b6), [`1b773e2a0`](1b773e2), [`3f32593c9`](3f32593)]: - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] ## [email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses ## [email protected] ### Patch Changes - [#2414](#2414) [`e7807485e`](e780748) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix dependencies so that the package correctly depends on all of the packages it uses Author: khan-actions-bot Reviewers: benchristel Required Reviewers: Approved By: benchristel Checks: ⏭️ 1 check has been skipped, ✅ 4 checks were successful Pull Request URL: #2412
Summary:
I realized that the type of the
defaulted
parser encouraged non-idempotentparsing. Essentially, a default value could be supplied that would cause a parse
error on a second pass through the parser. Example:
The inferred type
ParsedValue<typeof parseMyObject>
would be:However, the parser doesn't consider a myField value of type
string
to be valid!This contradicts the types! You will get an error if you try to parse
because the parser for
myField
only accepts a number, null, or undefined asinput.
This is clearly not how we want parsers to behave. Parsing should be idempotent.
This PR fixes the types of
defaulted
so we don't encourage non-idempotentparsing. It also adds tests to verify that our existing parsers are idempotent
when run on example data.
Issue: LEMS-3055
Test plan:
pnpm test