Skip to content

Commit

Permalink
Fix up a bunch of types
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremywiebe committed Dec 13, 2024
1 parent 5fdc3c7 commit c619dd8
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
UserInput,
UserInputArray,
UserInputMap,
ValidationData,
} from "./validation.types";
import type {WidgetPromptJSON} from "./widget-ai-utils/prompt-types";
import type {KeypadAPI} from "@khanacademy/math-input";
Expand Down Expand Up @@ -579,8 +580,8 @@ export type WidgetTransform = (
export type ValidationResult = Extract<PerseusScore, {type: "invalid"}> | null;

export type WidgetValidatorFunction = (
userInput: any, // STOPSHIP
validationData: any, // STOPHIP
userInput: UserInput,
validationData: ValidationData,
strings: PerseusStrings,
locale: string,
) => ValidationResult;
Expand Down
8 changes: 7 additions & 1 deletion packages/perseus/src/validation.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export type UserInput =
| PerseusDropdownUserInput
| PerseusExpressionUserInput
| PerseusGrapherUserInput
| PerseusGroupUserInput
| PerseusIFrameUserInput
| PerseusInputNumberUserInput
| PerseusInteractiveGraphUserInput
Expand All @@ -279,7 +280,7 @@ export type UserInput =
| PerseusSorterUserInput
| PerseusTableUserInput;

export type UserInputMap = {[widgetId: string]: UserInput | UserInputMap};
export type UserInputMap = {[widgetId: string]: UserInput};

/**
* deprecated prefer using UserInputMap
Expand Down Expand Up @@ -344,3 +345,8 @@ export type ValidationDataMap = {
options: ValidationDataTypes[Property];
};
};

/**
* A union type of all the different widget validation data types that exist.
*/
export type ValidationData = ValidationDataTypes[keyof ValidationDataTypes];
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets/categorizer/categorizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,7 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusCSProgramUserInput'.
scorer: scoreCategorizer,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusCSProgramUserInput'.
validator: validateCategorizer,
} satisfies WidgetExports<typeof Categorizer>;
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,7 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusDropdownUserInput'.
scorer: scoreDropdown,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusDropdownUserInput'.
validator: validateDropdown,
} satisfies WidgetExports<typeof Dropdown>;
3 changes: 2 additions & 1 deletion packages/perseus/src/widgets/expression/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export class Expression
_isMounted = false;

static getUserInputFromProps(props: Props): PerseusExpressionUserInput {
props; //?
return normalizeTex(props.value);
}

Expand Down Expand Up @@ -560,6 +559,8 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusExpressionUserInput'.
scorer: scoreExpression,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusExpressionUserInput'.
validator: validateExpression,

// TODO(LEMS-2656): remove TS suppression
Expand Down
4 changes: 3 additions & 1 deletion packages/perseus/src/widgets/group/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ export default {
widget: Group,
traverseChildWidgets: traverseChildWidgets,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusCSProgramUserInput'.
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusGroupUserInput'.
scorer: scoreGroup,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusGroupUserInput'.
validator: validateGroup,
hidden: true,
isLintable: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets/matrix/matrix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -601,5 +601,7 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusMatrixUserInput'.
scorer: scoreMatrix,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusMatrixUserInput'.
validator: validateMatrix,
} satisfies WidgetExports<typeof Matrix>;
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets/number-line/number-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -809,5 +809,7 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusNumberLineUserInput'.
scorer: scoreNumberLine,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusNumberLineUserInput'.
validator: validateNumberLine,
} satisfies WidgetExports<typeof NumberLine>;
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets/orderer/orderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -786,5 +786,7 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type UserInput is not assignable to type PerseusOrdererUserInput
scorer: scoreOrderer,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type UserInput is not assignable to type PerseusOrdererUserInput
validator: validateOrderer,
} satisfies WidgetExports<typeof Orderer>;
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets/plotter/plotter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1183,5 +1183,7 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type UserInput is not assignable to type PerseusPlotterUserInput
scorer: scorePlotter,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type UserInput is not assignable to type PerseusPlotterUserInput
validator: validatePlotter,
} satisfies WidgetExports<typeof Plotter>;
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,7 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type UserInput is not assignable to type PerseusRadioUserInput
scorer: scoreRadio,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type UserInput is not assignable to type PerseusRadioUserInput
validator: validateRadio,
} satisfies WidgetExports<typeof Radio>;
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets/sorter/sorter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,7 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type UserInput is not assignable to type PerseusSorterUserInput
scorer: scoreSorter,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type UserInput is not assignable to type PerseusSorterUserInput
validator: validateSorter,
} satisfies WidgetExports<typeof Sorter>;
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,7 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type UserInput is not assignable to type PerseusTableUserInput
scorer: scoreTable,
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type UserInput is not assignable to type PerseusTableUserInput
validator: validateTable,
} satisfies WidgetExports<typeof Table>;

0 comments on commit c619dd8

Please sign in to comment.