-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SSS: Improve types for validation (#2002)
## Summary: This PR begins working out the types for Scoring, Validation, and how they relate to our full widget options types. There are currently three "trees" of types that are shaped as a map of `widgetId` to something. They are: * Full widget options (starting from `PerseusRenderer`) * Scoring data - used to score the learner's guess (user input) * Validation data - a shared subset (of Render and Scoring data) used to do empty widget checking (aka validation). This helps the frontend to know if the question is scorable yet. Finally, there is also a widget map known as User Input. This map is a map of widget ids from the item to the user input the learner has entered so far. Issue: LEMS-2561 ## Test plan: `yarn typecheck` (especially, the new `validation.typetest.ts` file!) `yarn test` (just to be sure) Author: jeremywiebe Reviewers: jeremywiebe, Myranae, handeyeco Required Reviewers: Approved By: Myranae Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x) Pull Request URL: #2002
- Loading branch information
1 parent
e6f7cc9
commit a1e22a4
Showing
6 changed files
with
175 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
--- | ||
|
||
Add and improve types for scoring and validation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* This file contains TypeScript type "tests" which ensure that types needed | ||
* for scoring and validation stay in sync with other types in the system. | ||
* | ||
* If you make a change and `Extends<>` starts to complain, that will usually | ||
* mean you've made a change that will cause runtime breakages in scoring or | ||
* validation. ie. The types that should be compatible are no longer | ||
* compatible. Read the TypeScript error message closely and it should point | ||
* you in the right direction. | ||
*/ | ||
import type {PerseusRenderer} from "../perseus-types"; | ||
import type {ScoringDataMap, ValidationDataMap} from "../validation.types"; | ||
|
||
/** | ||
* An utility type that verifies that the given type `E` extends the type `T`. | ||
* This is useful for asserting that one type remains a compatible subset of | ||
* the other. | ||
*/ | ||
type Extends<T, E extends T> = (T) => E; | ||
|
||
// We can use a 'widgets' map from a PerseusRenderer as a ValidationDataMap | ||
type _ = Extends<ValidationDataMap, PerseusRenderer["widgets"]>; | ||
|
||
// We can use a ScoringDataMap as a ValidationDataMap | ||
type __ = Extends<ValidationDataMap, ScoringDataMap>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters