Skip to content

Commit

Permalink
fix: specify explicit type to prevent type issues at build (#2410)
Browse files Browse the repository at this point in the history
Our current declaration for `getTextChildren` are autogenerated since no
explicit type is declared, however the generated type causes type errors
since it directly reference the runtime:
```
export declare function getTextChildren(value: string): (string | import("@metamask/snaps-sdk/jsx-runtime").StandardFormattingElement | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").LinkProps, "Link"> | null)[];
```

We can work around this problem by specifying an explicit type
declaration for the function.
  • Loading branch information
FrederikBolding authored May 15, 2024
1 parent 00c2a50 commit 8df9a32
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/snaps-utils/src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import type {
FieldElement,
ItalicChildren,
JSXElement,
LinkElement,
MaybeArray,
RowChildren,
StandardFormattingElement,
TextChildren,
} from '@metamask/snaps-sdk/jsx';
import {
Expand Down Expand Up @@ -150,7 +152,9 @@ function getTextChildFromToken(token: Token): TextChildren {
* @param value - The markdown string.
* @returns The text children.
*/
export function getTextChildren(value: string) {
export function getTextChildren(
value: string,
): (string | StandardFormattingElement | LinkElement)[] {
const rootTokens = lexer(value, { gfm: false });
const children: TextChildren = [];

Expand All @@ -165,7 +169,11 @@ export function getTextChildren(value: string) {
}
});

return children.filter((child) => child !== null);
return children.filter((child) => child !== null) as (
| string
| StandardFormattingElement
| LinkElement
)[];
}

/**
Expand Down

0 comments on commit 8df9a32

Please sign in to comment.