Skip to content

Commit 2eb3208

Browse files
authored
Gutenboarding: Squash type errors (#38401)
* Don't create/clone/create for StepperWizard * Assert correct addQueryArgs type
1 parent d7f1c6f commit 2eb3208

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

client/landing/gutenboarding/onboarding-block/edit.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ const OnboardingEdit: FunctionComponent< BlockEditProps< Attributes > > = ( {
4444
! siteTitle &&
4545
NO__( "Let's set up your website – it takes only a moment." ) }
4646
</h2>
47-
<StepperWizard>
48-
<VerticalSelect />
49-
{ ( siteVertical || siteTitle ) && <SiteTitle /> }
50-
</StepperWizard>
47+
<StepperWizard
48+
stepComponents={ [ VerticalSelect, ( siteVertical || siteTitle ) && SiteTitle ] }
49+
/>
5150
{ siteVertical && (
5251
<div className="onboarding-block__footer">
5352
<Button className="onboarding-block__question-skip" isLink>

client/landing/gutenboarding/onboarding-block/site-title.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { __ as NO__ } from '@wordpress/i18n';
99
* Internal dependencies
1010
*/
1111
import { STORE_KEY } from '../stores/onboard';
12-
import { InjectedStepProps } from './stepper-wizard';
12+
import { StepProps } from './stepper-wizard';
1313
import Question from './question';
1414

15-
const SiteTitle: FunctionComponent< InjectedStepProps > = ( {
15+
const SiteTitle: FunctionComponent< StepProps > = ( {
1616
onSelect,
1717
inputClass,
1818
isActive,
Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
/**
22
* External dependencies
33
*/
4-
import React, { FunctionComponent, useState } from 'react';
4+
import React, { FunctionComponent, useState, ComponentType } from 'react';
5+
import { Falsy } from 'utility-types';
56

6-
export interface InjectedStepProps {
7+
export interface StepProps {
78
isActive: boolean;
89
onExpand: () => void;
910
onSelect: () => void;
1011
inputClass: string;
1112
}
1213

13-
const StepperWizard: FunctionComponent = ( { children } ) => {
14+
interface Props {
15+
stepComponents: Array< ComponentType< StepProps > | Falsy >;
16+
children?: never;
17+
}
18+
19+
const StepperWizard: FunctionComponent< Props > = ( { stepComponents } ) => {
1420
const [ activeStep, setActiveStep ] = useState( 0 );
1521

1622
const handleNext = () => setActiveStep( activeStep + 1 );
1723

1824
return (
1925
<>
20-
{ React.Children.map(
21-
children,
22-
( child, index ) =>
23-
React.isValidElement( child ) &&
24-
React.cloneElement< InjectedStepProps >( child, {
25-
isActive: index === activeStep,
26-
onExpand: () => setActiveStep( index ),
27-
onSelect: handleNext,
28-
inputClass: 'onboarding-block__question-input',
29-
} )
30-
) }
26+
{ stepComponents.map( ( Komponent, index ) => {
27+
return Komponent ? (
28+
<Komponent
29+
inputClass="onboarding-block__question-input"
30+
isActive={ index === activeStep }
31+
key={ index }
32+
onExpand={ () => setActiveStep( index ) }
33+
onSelect={ handleNext }
34+
/>
35+
) : null;
36+
} ) }
3137
</>
3238
);
3339
};
40+
3441
export default StepperWizard;

client/landing/gutenboarding/onboarding-block/vertical-select/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ENTER } from '@wordpress/keycodes';
1212
*/
1313
import { STORE_KEY } from '../../stores/onboard';
1414
import { SiteVertical } from '../../stores/onboard/types';
15-
import { InjectedStepProps } from '../stepper-wizard';
15+
import { StepProps } from '../stepper-wizard';
1616
import Question from '../question';
1717
import { __TodoAny__ } from '../../../../types';
1818

@@ -21,7 +21,7 @@ import { __TodoAny__ } from '../../../../types';
2121
*/
2222
import './style.scss';
2323

24-
const VerticalSelect: FunctionComponent< InjectedStepProps > = ( {
24+
const VerticalSelect: FunctionComponent< StepProps > = ( {
2525
onSelect,
2626
inputClass,
2727
isActive,

client/landing/gutenboarding/stores/domain-suggestions/resolvers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* External dependencies
33
*/
4-
import { addQueryArgs } from '@wordpress/url';
4+
import { addQueryArgs, InputArgsObject } from '@wordpress/url';
55
import { apiFetch } from '@wordpress/data-controls';
66

77
/**
@@ -25,7 +25,10 @@ export function* __internalGetDomainSuggestions(
2525
const suggestions = yield apiFetch( {
2626
credentials: 'same-origin',
2727
mode: 'cors',
28-
url: addQueryArgs( url, queryObject ),
28+
// Cast so we can use our closed interface without an index type.
29+
// It's likely the type definitions could be improved upstream to allow this:
30+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/dd4b4bf26c3bf43ea2df913efe70a427969f3731/types/wordpress__url/index.d.ts#L7-L54
31+
url: addQueryArgs( url, ( queryObject as unknown ) as InputArgsObject ),
2932
} );
3033

3134
return receiveDomainSuggestions( queryObject, suggestions );

0 commit comments

Comments
 (0)