diff --git a/packages/snaps-sdk/src/jsx/component.ts b/packages/snaps-sdk/src/jsx/component.ts index 386e8559fd..99f268dd84 100644 --- a/packages/snaps-sdk/src/jsx/component.ts +++ b/packages/snaps-sdk/src/jsx/component.ts @@ -1,4 +1,4 @@ -import type { Json, NonEmptyArray } from '@metamask/utils'; +import type { Json } from '@metamask/utils'; /** * A key, which can be a string or a number. @@ -48,7 +48,7 @@ export type SnapElement< * const maybeArrayString: MaybeArrayString = 'hello'; * const maybeArrayStringArray: MaybeArrayString = ['hello', 'world']; */ -export type MaybeArray = Type | NonEmptyArray; +export type MaybeArray = Type | Type[]; /** * A JSX node, which can be an element, a string, null, or an array of nodes. diff --git a/packages/snaps-sdk/src/jsx/validation.test.tsx b/packages/snaps-sdk/src/jsx/validation.test.tsx index 1587fab68d..716ca2ffbf 100644 --- a/packages/snaps-sdk/src/jsx/validation.test.tsx +++ b/packages/snaps-sdk/src/jsx/validation.test.tsx @@ -430,7 +430,6 @@ describe('BoxStruct', () => { [], // @ts-expect-error - Invalid props. , - // @ts-expect-error - Invalid props. , foo, @@ -765,7 +764,6 @@ describe('DropdownStruct', () => { [], // @ts-expect-error - Invalid props. , - // @ts-expect-error - Invalid props. , // @ts-expect-error - Invalid props. foo, diff --git a/packages/snaps-sdk/src/jsx/validation.ts b/packages/snaps-sdk/src/jsx/validation.ts index 3d59fc4124..258f491b2f 100644 --- a/packages/snaps-sdk/src/jsx/validation.ts +++ b/packages/snaps-sdk/src/jsx/validation.ts @@ -1,4 +1,3 @@ -import type { NonEmptyArray } from '@metamask/utils'; import { hasProperty, HexChecksumAddressStruct, @@ -86,11 +85,8 @@ export const ElementStruct: Describe = object({ */ function nonEmptyArray( struct: Struct, -): Struct, any> { - return nonempty(array(struct)) as unknown as Struct< - NonEmptyArray, - Schema - >; +): Struct> { + return nonempty(array(struct)); } /** diff --git a/packages/snaps-utils/src/ui.tsx b/packages/snaps-utils/src/ui.tsx index c0bfc53b5e..be2f59cfc0 100644 --- a/packages/snaps-utils/src/ui.tsx +++ b/packages/snaps-utils/src/ui.tsx @@ -2,7 +2,6 @@ import type { Component } from '@metamask/snaps-sdk'; import { NodeType } from '@metamask/snaps-sdk'; import type { BoldChildren, - FieldElement, ItalicChildren, JSXElement, LinkElement, @@ -29,7 +28,6 @@ import { Button, Address, } from '@metamask/snaps-sdk/jsx'; -import type { NonEmptyArray } from '@metamask/utils'; import { assert, assertExhaustive, @@ -67,7 +65,7 @@ function getButtonVariant(variant?: 'primary' | 'secondary' | undefined) { * @param elements - The JSX elements. * @returns The child or children. */ -function getChildren(elements: NonEmptyArray) { +function getChildren(elements: Type[]) { if (elements.length === 1) { return elements[0]; } @@ -83,11 +81,7 @@ function getChildren(elements: NonEmptyArray) { */ function getLinkText(token: Tokens.Link | Tokens.Generic) { if (token.tokens && token.tokens.length > 0) { - return getChildren( - token.tokens.flatMap( - getTextChildFromToken, - ) as NonEmptyArray, - ); + return getChildren(token.tokens.flatMap(getTextChildFromToken)); } return token.href; @@ -100,9 +94,7 @@ function getLinkText(token: Tokens.Link | Tokens.Generic) { * @returns The text child. */ function getTextChildFromTokens(tokens: Token[]) { - return getChildren( - tokens.flatMap(getTextChildFromToken) as NonEmptyArray, - ); + return getChildren(tokens.flatMap(getTextChildFromToken)); } /** @@ -161,7 +153,7 @@ function getTextChildFromToken(token: Token): TextChildren { */ export function getTextChildren( value: string, -): NonEmptyArray { +): (string | StandardFormattingElement | LinkElement)[] { const rootTokens = lexer(value, { gfm: false }); const children: (string | StandardFormattingElement | LinkElement | null)[] = []; @@ -177,9 +169,12 @@ export function getTextChildren( } }); - return children.filter((child) => child !== null) as NonEmptyArray< - string | StandardFormattingElement | LinkElement - >; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + return children.filter((child) => child !== null) as ( + | string + | StandardFormattingElement + | LinkElement + )[]; } /** @@ -249,9 +244,7 @@ export function getJsxElementFromComponent( case NodeType.Form: return (
- {getChildren( - component.children.map(getElement) as NonEmptyArray, - )} + {getChildren(component.children.map(getElement))} ); @@ -277,11 +270,7 @@ export function getJsxElementFromComponent( case NodeType.Panel: // `Panel` is renamed to `Box` in JSX. return ( - , - )} - /> + ); case NodeType.Row: