diff --git a/assets/js/base/components/cart-checkout/order-summary/order-summary-item.js b/assets/js/base/components/cart-checkout/order-summary/order-summary-item.js index 09e22cf06e5..5f48dbe3926 100644 --- a/assets/js/base/components/cart-checkout/order-summary/order-summary-item.js +++ b/assets/js/base/components/cart-checkout/order-summary/order-summary-item.js @@ -7,7 +7,6 @@ import ProductName from '@woocommerce/base-components/product-name'; import { getCurrencyFromPriceResponse } from '@woocommerce/price-format'; import { __experimentalApplyCheckoutFilter, - mustBeString, mustContain, Label, } from '@woocommerce/blocks-checkout'; @@ -48,7 +47,7 @@ const OrderSummaryItem = ( { cartItem } ) => { const { receiveCart, ...cart } = useStoreCart(); const productPriceValidation = useCallback( - ( value ) => mustBeString( value ) && mustContain( value, '' ), + ( value ) => mustContain( value, '' ), [] ); @@ -68,7 +67,6 @@ const OrderSummaryItem = ( { cartItem } ) => { defaultValue: initialName, extensions, arg, - validation: mustBeString, } ); const regularPriceSingle = Dinero( { diff --git a/assets/js/base/components/cart-checkout/totals/discount/index.js b/assets/js/base/components/cart-checkout/totals/discount/index.js index 44f6f9df448..ea1750e0a99 100644 --- a/assets/js/base/components/cart-checkout/totals/discount/index.js +++ b/assets/js/base/components/cart-checkout/totals/discount/index.js @@ -7,7 +7,6 @@ import { RemovableChip } from '@woocommerce/base-components/chip'; import PropTypes from 'prop-types'; import { __experimentalApplyCheckoutFilter, - mustBeString, TotalsItem, } from '@woocommerce/blocks-checkout'; import { getSetting } from '@woocommerce/settings'; @@ -60,7 +59,6 @@ const TotalsDiscount = ( { { cartCoupons.map( ( cartCoupon ) => { const filteredCouponCode = __experimentalApplyCheckoutFilter( { - validation: mustBeString, arg: { context: 'summary', coupon: cartCoupon, diff --git a/assets/js/base/components/cart-checkout/totals/footer-item/index.js b/assets/js/base/components/cart-checkout/totals/footer-item/index.js index 156b28473ec..1bedb27ab7e 100644 --- a/assets/js/base/components/cart-checkout/totals/footer-item/index.js +++ b/assets/js/base/components/cart-checkout/totals/footer-item/index.js @@ -7,7 +7,6 @@ import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-mone import PropTypes from 'prop-types'; import { __experimentalApplyCheckoutFilter, - mustBeString, TotalsItem, } from '@woocommerce/blocks-checkout'; import { useStoreCart } from '@woocommerce/base-context/hooks'; @@ -34,8 +33,6 @@ const TotalsFooterItem = ( { currency, values } ) => { defaultValue: __( 'Total', 'woo-gutenberg-products-block' ), extensions: cart.extensions, arg: { cart }, - // Only accept strings. - validation: mustBeString, } ); const parsedTaxValue = parseInt( totalTax, 10 ); diff --git a/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-item-row.tsx b/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-item-row.tsx index 0901fc3d003..4340a95df08 100644 --- a/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-item-row.tsx +++ b/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-item-row.tsx @@ -24,7 +24,6 @@ import { } from '@woocommerce/price-format'; import { __experimentalApplyCheckoutFilter, - mustBeString, mustContain, } from '@woocommerce/blocks-checkout'; import Dinero from 'dinero.js'; @@ -112,7 +111,7 @@ const CartLineItemRow = ( { const { dispatchStoreEvent } = useStoreEvents(); const productPriceValidation = useCallback( - ( value ) => mustBeString( value ) && mustContain( value, '' ), + ( value ) => mustContain( value, '' ), [] ); @@ -134,7 +133,6 @@ const CartLineItemRow = ( { defaultValue: initialName, extensions, arg, - validation: mustBeString, } ); const regularAmountSingle = Dinero( { diff --git a/packages/checkout/registry/index.ts b/packages/checkout/registry/index.ts index 6e92f00c0ae..0776a632687 100644 --- a/packages/checkout/registry/index.ts +++ b/packages/checkout/registry/index.ts @@ -74,7 +74,7 @@ export const __experimentalApplyCheckoutFilter = < T >( { /** Object containing arguments for the filter function. */ arg: CheckoutFilterArguments; /** Function that needs to return true when the filtered value is passed in order for the filter to be applied. */ - validation: ( value: unknown ) => true | Error; + validation?: ( value: T ) => true | Error; } ): T => { return useMemo( () => { const filters = getCheckoutFilters( filterName ); diff --git a/packages/checkout/utils/validation/index.ts b/packages/checkout/utils/validation/index.ts index 13ed7517764..48677339de2 100644 --- a/packages/checkout/utils/validation/index.ts +++ b/packages/checkout/utils/validation/index.ts @@ -3,25 +3,6 @@ */ import { __, sprintf } from '@wordpress/i18n'; -/** - * Checks if value passed is a string, throws an error if not. - */ -export const mustBeString = ( value: unknown ): true | Error => { - if ( typeof value !== 'string' ) { - throw Error( - sprintf( - /* translators: %s is type of value passed */ - __( - 'Returned value must be a string, you passed "%s"', - 'woo-gutenberg-products-block' - ), - typeof value - ) - ); - } - return true; -}; - /** * Checks if value passed contain passed label. */