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

Type fixes #1476

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/four-laws-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": patch
"@khanacademy/perseus-editor": patch
---

Miscellaneous type improvements
4 changes: 2 additions & 2 deletions packages/perseus-editor/src/article-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SectionControlButton from "./components/section-control-button";
import Editor from "./editor";
import IframeContentRenderer from "./iframe-content-renderer";

import type {APIOptions, Changeable} from "@khanacademy/perseus";
import type {APIOptions, Changeable, ImageUploader} from "@khanacademy/perseus";

const {HUD, InlineIcon} = components;
const {iconCircleArrowDown, iconCircleArrowUp, iconPlus, iconTrash} = icons;
Expand All @@ -39,7 +39,7 @@ type DefaultProps = {
};
type Props = DefaultProps & {
apiOptions?: APIOptions;
imageUploader?: (arg1: string, arg2: (arg1: string) => unknown) => unknown;
imageUploader?: ImageUploader;
// URL of the route to show on initial load of the preview frames.
previewURL: string;
} & Changeable.ChangeableProps;
Expand Down
11 changes: 6 additions & 5 deletions packages/perseus-editor/src/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import WidgetEditor from "./components/widget-editor";
import WidgetSelect from "./components/widget-select";
import TexErrorView from "./tex-error-view";

import type {ChangeHandler, PerseusWidget} from "@khanacademy/perseus";
import type {
ChangeHandler,
ImageUploader,
PerseusWidget,
} from "@khanacademy/perseus";

// like [[snowman input-number 1]]
const widgetPlaceholder = "[[\u2603 {id}]]";
Expand Down Expand Up @@ -122,10 +126,7 @@ type Props = Readonly<{
showWordCount: boolean;
warnNoPrompt: boolean;
warnNoWidgets: boolean;
imageUploader?: (
file: string,
callback: (url: string) => unknown,
) => unknown;
imageUploader?: ImageUploader;
onChange: ChangeHandler;
}>;

Expand Down
6 changes: 1 addition & 5 deletions packages/perseus-editor/src/hint-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ import type {
Hint,
ChangeHandler,
DeviceType,
ImageUploader,
} from "@khanacademy/perseus";

const {InfoTip, InlineIcon} = components;
const {iconCircleArrowDown, iconCircleArrowUp, iconPlus, iconTrash} = icons;

type ImageUploader = (
file: string,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a duplicate type, but it also typed file incorrectly (it should be File).

callback: (url: string) => unknown,
) => unknown;

type HintEditorProps = {
itemId?: string;
apiOptions?: APIOptions;
Expand Down
3 changes: 2 additions & 1 deletion packages/perseus-editor/src/item-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
ImageUploader,
ChangeHandler,
DeviceType,
PerseusRenderer,
} from "@khanacademy/perseus";

const ITEM_DATA_VERSION = itemDataVersion;
Expand All @@ -22,7 +23,7 @@ type Props = {
gradeMessage?: string;
imageUploader?: ImageUploader;
wasAnswered?: boolean;
question?: any;
question?: PerseusRenderer;
answerArea?: any;
// URL of the route to show on initial load of the preview frames.
previewURL: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import type {
PerseusRenderer,
APIOptions,
} from "@khanacademy/perseus";
import type {Meta, StoryObj} from "@storybook/react";

type StoryArgs = Record<any, any>;
type StoryArgs = StoryObj<RadioEditor>;

type Story = {
title: string;
};
type Story = Meta<RadioEditor>;

export default {
title: "PerseusEditor/Widgets/Radio Editor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
} from "../__testdata__/server-item-renderer.testdata";
import {ServerItemRenderer} from "../server-item-renderer";

type StoryArgs = Record<any, any>;
import type {StoryObj, Meta} from "@storybook/react";

type Story = {
title: string;
};
type StoryArgs = StoryObj<ServerItemRenderer>;

type Story = Meta<ServerItemRenderer>;

export default {
title: "Perseus/Renderers/Server Item Renderer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as React from "react";

import ButtonGroup from "../button-group";

type StoryArgs = Record<any, any>;
import type {Meta, StoryObj} from "@storybook/react";

type Story = {
title: string;
};
type StoryArgs = StoryObj<ButtonGroup>;

type Story = Meta<ButtonGroup>;

export default {
title: "Perseus/Components/Button Group",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as React from "react";
import {getDependencies} from "../../dependencies";
import FixedToResponsive from "../fixed-to-responsive";

type StoryArgs = Record<any, any>;
import type {Meta, StoryObj} from "@storybook/react";

type Story = {
title: string;
};
type StoryArgs = StoryObj<FixedToResponsive>;

type Story = Meta<FixedToResponsive>;

const svgUrl = "https://www.khanacademy.org/images/ohnoes-concerned.svg";
const imgUrl = "https://www.khanacademy.org/images/hand-tree.new.png";
Expand Down
8 changes: 4 additions & 4 deletions packages/perseus/src/components/__stories__/graph.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as React from "react";

import Graph from "../graph";

type StoryArgs = Record<any, any>;
import type {StoryObj, Meta} from "@storybook/react";

type Story = {
title: string;
};
type StoryArgs = StoryObj<Graph>;

type Story = Meta<Graph>;

const size = 200;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {ServerItemRendererWithDebugUI} from "../../../../../testing/server-item-
import {itemWithPieChart} from "../../__testdata__/graphie.testdata";
import Graphie from "../graphie";

type StoryArgs = Record<any, any>;
import type {StoryObj, Meta} from "@storybook/react";

type Story = {
title: string;
};
type StoryArgs = StoryObj<Graphie>;

type Story = Meta<Graphie>;

const size = 200;

Expand Down
8 changes: 4 additions & 4 deletions packages/perseus/src/components/__stories__/hud.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as React from "react";

import Hud from "../hud";

type StoryArgs = Record<any, any>;
import type {StoryObj, Meta} from "@storybook/react";

type Story = {
title: string;
};
type StoryArgs = StoryObj<typeof Hud>;

type Story = Meta<typeof Hud>;

export default {
title: "Perseus/Components/HUD",
Expand Down
31 changes: 3 additions & 28 deletions packages/perseus/src/components/__stories__/icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,11 @@ import * as React from "react";
import * as IconPaths from "../../icon-paths";
import IconComponent from "../icon";

type StorybookStoryArgs = {
options?: ReadonlyArray<string>;
mapping?: {
[value: string]: any;
};
defaultValue?: string;
control?: string;
};
import type {StoryObj, Meta} from "@storybook/react";

type StoryArgs = {
color?: string;
size?: number;
title?: string;
icon?: typeof IconPaths.iconCheck;
};
type StoryArgs = StoryObj<IconComponent>;

type SetValueType<T, V> = {
[Property in keyof T]: V;
};

type StoryArgTypes = SetValueType<
StoryArgs,
StorybookStoryArgs | null | undefined
>;

type Story = {
title: string;
args?: StoryArgs;
argTypes: StoryArgTypes;
};
type Story = Meta<IconComponent>;

export default {
title: "Perseus/Components",
Expand Down
3 changes: 2 additions & 1 deletion packages/perseus/src/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import type {
PerseusScore,
WidgetProps,
} from "./types";
import type {KeypadAPI} from "@khanacademy/math-input";
import type {LinterContextProps} from "@khanacademy/perseus-linter";

import "./styles/perseus-renderer.less";
Expand Down Expand Up @@ -169,7 +170,7 @@ type Props = Partial<React.ContextType<typeof DependenciesContext>> & {
findExternalWidgets: any;
highlightedWidgets?: ReadonlyArray<any>;
images: PerseusRenderer["images"];
keypadElement?: any; // TODO(kevinb): add proper types,
keypadElement?: KeypadAPI | null;
onInteractWithWidget: (id: string) => void;
onRender: (node?: any) => void;
problemNum?: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export type ChangeHandler = (
) => unknown;

export type ImageUploader = (
file: string,
file: File,
callback: (url: string) => unknown,
) => unknown;

Expand Down