From 8df9a3254c7ec66d7fc6ab420da370234f9f5401 Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Wed, 15 May 2024 17:01:10 +0200 Subject: [PATCH] fix: specify explicit type to prevent type issues at build (#2410) 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 | null)[]; ``` We can work around this problem by specifying an explicit type declaration for the function. --- packages/snaps-utils/src/ui.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/snaps-utils/src/ui.tsx b/packages/snaps-utils/src/ui.tsx index 4394dd69d7..cad94f4d53 100644 --- a/packages/snaps-utils/src/ui.tsx +++ b/packages/snaps-utils/src/ui.tsx @@ -5,8 +5,10 @@ import type { FieldElement, ItalicChildren, JSXElement, + LinkElement, MaybeArray, RowChildren, + StandardFormattingElement, TextChildren, } from '@metamask/snaps-sdk/jsx'; import { @@ -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 = []; @@ -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 + )[]; } /**