From 6252b951e3c1ab26c4603e4972692cccb3b1614a Mon Sep 17 00:00:00 2001
From: Thomas Roberts <5656702+opr@users.noreply.github.com>
Date: Wed, 9 Nov 2022 10:26:28 +0000
Subject: [PATCH] Fix TypeScript errors in `CartLineItemRow`
(https://github.com/woocommerce/woocommerce-blocks/pull/7605)
* Import Currency type from correct location
* Add type for productPriceValidation argument
* Default tabIndex to undefined
null is not an acceptable value for the tabIndex prop, but undefined is, so we should use that.
* Explicitly set type of CartLineItemRow to ForwardRefExoticComponent
* bot: update checkstyle.xml
* Change CartLineItemRow to extend React.RefAttributes
* bot: update checkstyle.xml
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
---
.../cart-line-item-row.tsx | 17 ++++++++---------
plugins/woocommerce-blocks/checkstyle.xml | 6 ------
2 files changed, 8 insertions(+), 15 deletions(-)
diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart/cart-line-items-table/cart-line-item-row.tsx b/plugins/woocommerce-blocks/assets/js/blocks/cart/cart-line-items-table/cart-line-item-row.tsx
index 77af1e8422d..975dcaaef9b 100644
--- a/plugins/woocommerce-blocks/assets/js/blocks/cart/cart-line-items-table/cart-line-item-row.tsx
+++ b/plugins/woocommerce-blocks/assets/js/blocks/cart/cart-line-items-table/cart-line-item-row.tsx
@@ -19,10 +19,7 @@ import {
ProductMetadata,
ProductSaleBadge,
} from '@woocommerce/base-components/cart-checkout';
-import {
- getCurrencyFromPriceResponse,
- Currency,
-} from '@woocommerce/price-format';
+import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import {
__experimentalApplyCheckoutFilter,
mustContain,
@@ -30,7 +27,7 @@ import {
import Dinero from 'dinero.js';
import { forwardRef, useMemo } from '@wordpress/element';
import type { CartItem } from '@woocommerce/type-defs/cart';
-import { objectHasProp } from '@woocommerce/types';
+import { objectHasProp, Currency } from '@woocommerce/types';
import { getSetting } from '@woocommerce/settings';
/**
@@ -47,7 +44,8 @@ const getAmountFromRawPrice = (
return priceObject.convertPrecision( currency.minorUnit ).getAmount();
};
-const productPriceValidation = ( value ) => mustContain( value, '' );
+const productPriceValidation = ( value: string ) =>
+ mustContain( value, '' );
interface CartLineItemRowProps {
lineItem: CartItem | Record< string, never >;
@@ -58,9 +56,11 @@ interface CartLineItemRowProps {
/**
* Cart line item table row component.
*/
-const CartLineItemRow = forwardRef< HTMLTableRowElement, CartLineItemRowProps >(
+const CartLineItemRow: React.ForwardRefExoticComponent<
+ CartLineItemRowProps & React.RefAttributes< HTMLTableRowElement >
+> = forwardRef< HTMLTableRowElement, CartLineItemRowProps >(
(
- { lineItem, onRemove = () => void null, tabIndex = null },
+ { lineItem, onRemove = () => void null, tabIndex },
ref
): JSX.Element => {
const {
@@ -367,5 +367,4 @@ const CartLineItemRow = forwardRef< HTMLTableRowElement, CartLineItemRowProps >(
);
}
);
-
export default CartLineItemRow;
diff --git a/plugins/woocommerce-blocks/checkstyle.xml b/plugins/woocommerce-blocks/checkstyle.xml
index a4ad066c9b9..476087d5a25 100644
--- a/plugins/woocommerce-blocks/checkstyle.xml
+++ b/plugins/woocommerce-blocks/checkstyle.xml
@@ -2369,12 +2369,6 @@
Argument of type '{ icon: { src: JSX.Element; }; edit: ({ clientId }: Props) => JSX.Element; save: () => JSX.Element; }' is not assignable to parameter of type 'BlockConfiguration<{}>'.
Type '{ icon: { src: Element; }; edit: ({ clientId }: Props) => Element; save: () => Element; }' is missing the following properties from type 'Pick<Block<{}>, "title" | "category" | "attributes">': title, category, attributes" source="TS2769" />
-
-
-
-
-