Skip to content

Commit

Permalink
fix: correctly type awaitComponent and mdAwait
Browse files Browse the repository at this point in the history
  • Loading branch information
dbartholomae committed Oct 15, 2020
1 parent ee972f1 commit 70ba448
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/awaitComponent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ describe("awaitComponent", () => {
expect(await render(<AsyncText />)).toEqual("Test");
});

it("renders an async component resolving to null", async () => {
const AsyncText: Component = awaitComponent(async () => null);
expect(await render(<AsyncText />)).toEqual("");
});

it("passes through all props", async () => {
interface Props {
children: string;
Expand Down
4 changes: 2 additions & 2 deletions src/awaitComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @jsx MD */
import MD, { Component, MdFunctionElement } from ".";
import MD, { Component, MarkdownElement } from ".";

/**
* Wraps a function that returns a promise to be a valid component
Expand All @@ -14,7 +14,7 @@ import MD, { Component, MdFunctionElement } from ".";
* ```
*/
export function awaitComponent<Props>(
componentFn: (props: Props) => Promise<MdFunctionElement<Props>>
componentFn: (props: Props) => Promise<MarkdownElement<Props> | null>
): Component<Props> {
/* eslint-disable-next-line react/display-name */
return (props: Props) => <mdAwait>{componentFn(props)}</mdAwait>;
Expand Down
3 changes: 2 additions & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ declare global {
children?: MarkdownChildren;
};
mdAwait: {
children?: Promise<MdFunctionElement>;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
children?: Promise<MarkdownElement<any> | null>;
};
}
}
Expand Down

0 comments on commit 70ba448

Please sign in to comment.