Fix type errors in ./client after migrating options store to TS

This commit is contained in:
Chi-Hsuan Huang 2022-05-24 11:20:04 +08:00
parent 5f7d0cd0e1
commit 55dfa78ebb
6 changed files with 18 additions and 12 deletions

View File

@ -104,7 +104,6 @@ const NoThanksButton = () => {
); );
updateOptions( { updateOptions( {
[ dismissOptionKey ]: 'yes', [ dismissOptionKey ]: 'yes',
// @ts-expect-error updateOptions returns a Promise, but it is not typed in source.
} ).then( () => { } ).then( () => {
window.location.href = noThanksUrl; window.location.href = noThanksUrl;
} ); } );

View File

@ -135,7 +135,6 @@ const Tax: React.FC< TaxProps > = ( { onComplete, query, task } ) => {
updateOptions( { updateOptions( {
woocommerce_no_sales_tax: true, woocommerce_no_sales_tax: true,
woocommerce_calc_taxes: 'no', woocommerce_calc_taxes: 'no',
// @ts-expect-error updateOptions returns a Promise, but it is not typed in source.
} ).then( () => { } ).then( () => {
window.location.href = getAdminLink( 'admin.php?page=wc-admin' ); window.location.href = getAdminLink( 'admin.php?page=wc-admin' );
} ); } );

View File

@ -15,7 +15,12 @@ import { useEffect } from '@wordpress/element';
*/ */
import { createNoticesFromResponse } from '~/lib/notices'; import { createNoticesFromResponse } from '~/lib/notices';
import { SetupStepProps } from './setup'; import { SetupStepProps } from './setup';
import { SettingsSelector } from '../utils';
const isWcConnectOptions = (
wcConnectOptions: unknown
): wcConnectOptions is {
[ key: string ]: unknown;
} => typeof wcConnectOptions === 'object' && wcConnectOptions !== null;
export const Plugins: React.FC< SetupStepProps > = ( { export const Plugins: React.FC< SetupStepProps > = ( {
nextStep, nextStep,
@ -27,7 +32,8 @@ export const Plugins: React.FC< SetupStepProps > = ( {
const { isResolving, tosAccepted } = useSelect( ( select ) => { const { isResolving, tosAccepted } = useSelect( ( select ) => {
const { getOption, hasFinishedResolution } = select( const { getOption, hasFinishedResolution } = select(
OPTIONS_STORE_NAME OPTIONS_STORE_NAME
) as SettingsSelector; );
const wcConnectOptions = getOption( 'wc_connect_options' );
return { return {
isResolving: isResolving:
@ -38,7 +44,8 @@ export const Plugins: React.FC< SetupStepProps > = ( {
'wc_connect_options', 'wc_connect_options',
] ), ] ),
tosAccepted: tosAccepted:
getOption( 'wc_connect_options' )?.tos_accepted || ( isWcConnectOptions( wcConnectOptions ) &&
wcConnectOptions?.tos_accepted ) ||
getOption( 'woocommerce_setup_jetpack_opted_in' ) === '1', getOption( 'woocommerce_setup_jetpack_opted_in' ) === '1',
}; };
} ); } );

View File

@ -51,9 +51,7 @@ export const Setup: React.FC< SetupProps > = ( {
const { getSettings } = select( const { getSettings } = select(
SETTINGS_STORE_NAME SETTINGS_STORE_NAME
) as SettingsSelector; ) as SettingsSelector;
const { hasFinishedResolution } = select( const { hasFinishedResolution } = select( OPTIONS_STORE_NAME );
OPTIONS_STORE_NAME
) as SettingsSelector;
const { getActivePlugins } = select( PLUGINS_STORE_NAME ); const { getActivePlugins } = select( PLUGINS_STORE_NAME );
return { return {

View File

@ -2,7 +2,7 @@
* External dependencies * External dependencies
*/ */
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
import { OPTIONS_STORE_NAME, TaskType } from '@woocommerce/data'; import { ONBOARDING_STORE_NAME, TaskType } from '@woocommerce/data';
import { TaskItem, useSlot } from '@woocommerce/experimental'; import { TaskItem, useSlot } from '@woocommerce/experimental';
import { useCallback } from '@wordpress/element'; import { useCallback } from '@wordpress/element';
import { useDispatch } from '@wordpress/data'; import { useDispatch } from '@wordpress/data';
@ -26,7 +26,9 @@ export const TaskListItemTwoColumn: React.FC< TaskListItemProps > = ( {
trackClick, trackClick,
} ) => { } ) => {
const { createNotice } = useDispatch( 'core/notices' ); const { createNotice } = useDispatch( 'core/notices' );
const { dismissTask, undoDismissTask } = useDispatch( OPTIONS_STORE_NAME ); const { dismissTask, undoDismissTask } = useDispatch(
ONBOARDING_STORE_NAME
);
const { const {
id: taskId, id: taskId,

View File

@ -31,13 +31,14 @@ export const TaskListItem: React.FC< TaskListItemProps > = ( {
eventPrefix, eventPrefix,
} ) => { } ) => {
const { createNotice } = useDispatch( 'core/notices' ); const { createNotice } = useDispatch( 'core/notices' );
const { const {
visitedTask,
dismissTask, dismissTask,
undoDismissTask, undoDismissTask,
snoozeTask, snoozeTask,
undoSnoozeTask, undoSnoozeTask,
} = useDispatch( OPTIONS_STORE_NAME ); } = useDispatch( ONBOARDING_STORE_NAME );
const { visitedTask } = useDispatch( ONBOARDING_STORE_NAME );
const slot = useSlot( const slot = useSlot(
`woocommerce_onboarding_task_list_item_${ task.id }` `woocommerce_onboarding_task_list_item_${ task.id }`