Change woocommerce data async action error type to unknown

This commit is contained in:
Chi-Hsuan Huang 2022-05-10 16:53:51 +08:00
parent ef9af07bde
commit e179f8d1fe
8 changed files with 17 additions and 25 deletions

View File

@ -3,7 +3,6 @@
*/
import TYPES from './action-types';
import { Locales, Country } from './types';
import { RestApiError } from '../types';
export function getLocalesSuccess( locales: Locales ) {
return {
@ -12,7 +11,7 @@ export function getLocalesSuccess( locales: Locales ) {
};
}
export function getLocalesError( error: RestApiError ) {
export function getLocalesError( error: unknown ) {
return {
type: TYPES.GET_LOCALES_ERROR as const,
error,
@ -26,7 +25,7 @@ export function getCountriesSuccess( countries: Country[] ) {
};
}
export function getCountriesError( error: RestApiError ) {
export function getCountriesError( error: unknown ) {
return {
type: TYPES.GET_COUNTRIES_ERROR as const,
error,

View File

@ -16,7 +16,6 @@ import {
import { NAMESPACE } from '../constants';
import { Locales, Country } from './types';
import { STORE_NAME } from './constants';
import { RestApiError } from '../types';
const resolveSelect =
controls && controls.resolveSelect ? controls.resolveSelect : select;
@ -35,7 +34,7 @@ export function* getLocales() {
return getLocalesSuccess( results );
} catch ( error ) {
return getLocalesError( error as RestApiError );
return getLocalesError( error );
}
}
@ -53,6 +52,6 @@ export function* getCountries() {
return getCountriesSuccess( results );
} catch ( error ) {
return getCountriesError( error as RestApiError );
return getCountriesError( error );
}
}

View File

@ -41,7 +41,7 @@ export type Locales = {
export type CountriesState = {
errors: {
[ key: string ]: string | RestApiError | undefined;
[ key: string ]: unknown;
};
locales: Locales;
countries: Country[];

View File

@ -9,7 +9,6 @@ import { apiFetch } from '@wordpress/data-controls';
import { ACTION_TYPES } from './action-types';
import { API_NAMESPACE } from './constants';
import { PaymentGateway } from './types';
import { RestApiError } from '../types';
export function getPaymentGatewaysRequest(): {
type: ACTION_TYPES.GET_PAYMENT_GATEWAYS_REQUEST;
@ -32,10 +31,10 @@ export function getPaymentGatewaysSuccess(
}
export function getPaymentGatewaysError(
error: RestApiError
error: unknown
): {
type: ACTION_TYPES.GET_PAYMENT_GATEWAYS_ERROR;
error: RestApiError;
error: unknown;
} {
return {
type: ACTION_TYPES.GET_PAYMENT_GATEWAYS_ERROR,
@ -52,10 +51,10 @@ export function getPaymentGatewayRequest(): {
}
export function getPaymentGatewayError(
error: RestApiError
error: unknown
): {
type: ACTION_TYPES.GET_PAYMENT_GATEWAY_ERROR;
error: RestApiError;
error: unknown;
} {
return {
type: ACTION_TYPES.GET_PAYMENT_GATEWAY_ERROR,
@ -95,10 +94,10 @@ export function updatePaymentGatewayRequest(): {
}
export function updatePaymentGatewayError(
error: RestApiError
error: unknown
): {
type: ACTION_TYPES.UPDATE_PAYMENT_GATEWAY_ERROR;
error: RestApiError;
error: unknown;
} {
return {
type: ACTION_TYPES.UPDATE_PAYMENT_GATEWAY_ERROR,
@ -127,7 +126,7 @@ export function* updatePaymentGateway(
return response;
}
} catch ( e ) {
yield updatePaymentGatewayError( e as RestApiError );
yield updatePaymentGatewayError( e );
throw e;
}
}

View File

@ -21,7 +21,6 @@ import {
import { API_NAMESPACE, STORE_KEY } from './constants';
import { PaymentGateway } from './types';
import { RestApiError } from '../types';
// Can be removed in WP 5.9.
const dispatch =
@ -44,7 +43,7 @@ export function* getPaymentGateways() {
);
}
} catch ( e ) {
yield getPaymentGatewaysError( e as RestApiError );
yield getPaymentGatewaysError( e );
}
}
@ -61,6 +60,6 @@ export function* getPaymentGateway( id: string ) {
return response;
}
} catch ( e ) {
yield getPaymentGatewayError( e as RestApiError );
yield getPaymentGatewayError( e );
}
}

View File

@ -2,7 +2,7 @@
* Internal dependencies
*/
import { PaymentGateway, PluginsState } from './types';
import { RestApiError, WPDataSelector, WPDataSelectors } from '../types';
import { WPDataSelector, WPDataSelectors } from '../types';
export function getPaymentGateway(
state: PluginsState,
@ -22,7 +22,7 @@ export function getPaymentGateways(
export function getPaymentGatewayError(
state: PluginsState,
selector: string
): RestApiError | null {
): unknown | null {
return state.errors[ selector ] || null;
}

View File

@ -18,9 +18,6 @@ const defaultState: PluginsState = {
const restApiError = {
code: 'error code',
data: {
status: 400,
},
message: 'error message',
};

View File

@ -1,7 +1,6 @@
/**
* Internal dependencies
*/
import { RestApiError } from '../types';
export type SettingDefinition = {
default: string;
@ -31,5 +30,5 @@ export type PaymentGateway = {
export type PluginsState = {
paymentGateways: PaymentGateway[];
isUpdating: boolean;
errors: Record< string, RestApiError >;
errors: Record< string, unknown >;
};