From 27a15d097c8a85117c1a0967ac7c6c805aede304 Mon Sep 17 00:00:00 2001 From: Yashvardhan Jagnani <60016972+jagnani73@users.noreply.github.com> Date: Wed, 23 Oct 2024 19:05:50 +0530 Subject: [PATCH] wip-fix: actionables type (#227) --- src/utils/functions/actionable-wrapper.ts | 6 ++--- src/utils/types/shared.types.ts | 33 ++++++++++++----------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/utils/functions/actionable-wrapper.ts b/src/utils/functions/actionable-wrapper.ts index 1ff34703..28bc01c0 100644 --- a/src/utils/functions/actionable-wrapper.ts +++ b/src/utils/functions/actionable-wrapper.ts @@ -1,9 +1,7 @@ import { type ActionableType } from "../types/shared.types"; -import { createElement } from "react"; +import { createElement, type ElementType } from "react"; -export const actionableWrapper = < - T extends keyof JSX.IntrinsicElements | React.ComponentType, ->( +export const actionableWrapper = ( actionable: ActionableType | null, children: React.ReactNode, ): React.ReactNode => { diff --git a/src/utils/types/shared.types.ts b/src/utils/types/shared.types.ts index ea9e8aa3..09bbdb92 100644 --- a/src/utils/types/shared.types.ts +++ b/src/utils/types/shared.types.ts @@ -1,15 +1,17 @@ import { type Option } from "@/utils/option"; import type { NftApprovalsItem, + Pagination, TokensApprovalItem, + Transaction, } from "@covalenthq/client-sdk"; -import { type Pagination, type Transaction } from "@covalenthq/client-sdk"; -import { - type Column, - type ColumnDef, - type Row, - type SortingState, +import type { + Column, + ColumnDef, + Row, + SortingState, } from "@tanstack/react-table"; +import type { ComponentType } from "react"; export interface BalancePriceDeltaProps { numerator: number; @@ -99,12 +101,13 @@ export interface HeadingProps size: 1 | 2 | 3 | 4; } -export type ActionableType< - T extends - | keyof JSX.IntrinsicElements - | React.ComponentType = keyof JSX.IntrinsicElements, -> = - | (T extends keyof JSX.IntrinsicElements - ? { parent: T; parentProps: JSX.IntrinsicElements[T] } - : { parent: T; parentProps: React.ComponentProps }) - | null; +export type ElementType = keyof JSX.IntrinsicElements | ComponentType; + +export type ActionableType = { + parent: T; + parentProps: T extends keyof JSX.IntrinsicElements + ? JSX.IntrinsicElements[T] + : T extends ComponentType + ? P + : never; +} | null;