Skip to content

Commit 68e55bb

Browse files
authored
Merge pull request #1388 from Shopify/typescript-update
Updating to typescript 3.2
2 parents b703163 + 10b2800 commit 68e55bb

File tree

17 files changed

+85
-281
lines changed

17 files changed

+85
-281
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"allowBlockStart": false
2929
}
3030
],
31+
"import/named": "off",
3132
"import/no-named-as-default": "off",
3233
"react/button-has-type": "off",
3334
"react/no-array-index-key": "off",

UNRELEASED.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
4747
- Update most devDependencies ([#1327](https://github.com/Shopify/polaris-react/pull/1327))
4848
- Bump react-utilites to remove a transitive dependency on core-js. ([#1343](https://github.com/Shopify/polaris-react/pull/1343))
4949
- Updated App Bridge to version 1.3.0 ([#1349](https://github.com/Shopify/polaris-react/pull/1349))
50+
- Updated typescript to 3.2.4 ([#1388](https://github.com/Shopify/polaris-react/pull/1388))
5051

5152
### Code quality
5253

config/typescript/prop-types.d.ts

-5
This file was deleted.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@
155155
"shelljs": "^0.8.3",
156156
"shx": "^0.3.2",
157157
"svgo": "^1.2.2",
158-
"typescript": "~3.1.6",
158+
"typescript": "~3.2.4",
159159
"yargs": "^13.2.2"
160160
},
161161
"peerDependencies": {
162162
"react": "^16.3.1",
163163
"react-dom": "^16.3.1"
164164
},
165165
"resolutions": {
166-
"typescript-eslint-parser": "20.0.0"
166+
"typescript-eslint-parser": "22.0.0"
167167
},
168168
"files": [
169169
"esnext",
@@ -182,9 +182,9 @@
182182
"@shopify/javascript-utilities": "^2.2.1",
183183
"@shopify/polaris-icons": "^3.3.0",
184184
"@shopify/polaris-tokens": "^2.5.0",
185-
"@shopify/react-compose": "^0.1.6",
185+
"@shopify/react-compose": "^1.0.0",
186186
"@shopify/react-utilities": "^2.0.4",
187-
"@types/prop-types": "^15.5.5",
187+
"@shopify/useful-types": "^1.2.4",
188188
"@types/react": "^16.4.7",
189189
"@types/react-dom": "^16.0.6",
190190
"@types/react-transition-group": "^2.0.7",

src/components/ActionList/ActionList.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export default function ActionList({
3030
}
3131

3232
const hasMultipleSections = finalSections.length > 1;
33-
const Element: string = hasMultipleSections ? 'ul' : 'div';
33+
// Type asserting to any is required for TS3.2 but can be removed when we update to 3.3
34+
// see https://github.com/Microsoft/TypeScript/issues/28768
35+
const Element: any = hasMultipleSections ? 'ul' : 'div';
3436
const sectionMarkup = finalSections.map((section, index) => {
3537
return (
3638
<Section

src/components/AppProvider/tests/AppProvider.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('<AppProvider />', () => {
3636
}
3737
}
3838

39-
const wrapper = TestUtils.renderIntoDocument(
39+
const wrapper: unknown = TestUtils.renderIntoDocument(
4040
<AppProvider i18n={i18n} linkComponent={CustomLinkComponent}>
4141
<Child />
4242
</AppProvider>,

src/components/AppProvider/utilities/withAppProvider/withAppProvider.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export default function withAppProvider<OwnProps>() {
7575
);
7676
}
7777

78-
return <WrappedComponent {...this.props} polaris={polarisContext} />;
78+
return (
79+
<WrappedComponent {...this.props as any} polaris={polarisContext} />
80+
);
7981
}
8082

8183
private handleContextUpdate = () => {

src/components/AppProvider/utilities/withSticky/withSticky.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ export default function withSticky() {
4141

4242
render() {
4343
return (
44-
<WrappedComponent {...this.props} polaris={this.polarisContext} />
44+
<WrappedComponent
45+
{...this.props as any}
46+
polaris={this.polarisContext}
47+
/>
4548
);
4649
}
4750
}

src/components/ChoiceList/ChoiceList.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ function ChoiceList({
5959
error,
6060
name = getUniqueID(),
6161
}: CombinedProps) {
62-
const ControlComponent: typeof Checkbox | typeof RadioButton = allowMultiple
63-
? Checkbox
64-
: RadioButton;
62+
// Type asserting to any is required for TS3.2 but can be removed when we update to 3.3
63+
// see https://github.com/Microsoft/TypeScript/issues/28768
64+
const ControlComponent: any = allowMultiple ? Checkbox : RadioButton;
6565

6666
const finalName = allowMultiple ? `${name}[]` : name;
6767

src/components/Connected/Connected.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface State {
1818

1919
export default function Connected({children, left, right}: Props) {
2020
if (left == null && right == null) {
21-
return React.Children.only(children);
21+
return <React.Fragment>{children}</React.Fragment>;
2222
}
2323

2424
const leftConnectionMarkup = left ? (

src/components/Icon/Icon.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function Icon({
218218
const defaultIconProps = {
219219
className: styles.Svg,
220220
focusable: 'false',
221-
'aria-hidden': 'true',
221+
'aria-hidden': 'true' as 'true',
222222
};
223223

224224
if (untrusted) {

src/components/Popover/Popover.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default class Popover extends React.PureComponent<Props, State> {
7575

7676
render() {
7777
const {
78-
activatorWrapper: WrapperComponent = 'div',
78+
activatorWrapper: WrapperComponent = 'div' as any,
7979
children,
8080
onClose,
8181
activator,

src/components/ThemeProvider/tests/ThemeProvider.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('<ThemeProvider />', () => {
3838
}
3939
}
4040

41-
const wrapper = TestUtils.renderIntoDocument(
41+
const wrapper: unknown = TestUtils.renderIntoDocument(
4242
<ThemeProvider
4343
theme={{
4444
logo: {

src/components/Tooltip/Tooltip.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default class Tooltip extends React.PureComponent<Props, State> {
6060
content,
6161
light,
6262
preferredPosition = 'below',
63-
activatorWrapper: WrapperComponent = 'span',
63+
activatorWrapper: WrapperComponent = 'span' as any,
6464
} = this.props;
6565

6666
const {active, activatorNode} = this.state;

src/components/WithRef/WithRef.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import hoistStatics from 'hoist-non-react-statics';
33
import {ReactComponent} from '@shopify/react-utilities/types';
4+
import {NonReactStatics} from '@shopify/useful-types';
45
import {Consumer} from './components';
56

67
export type ComponentType<P> = React.ComponentClass<P> | React.SFC<P>;
@@ -12,13 +13,14 @@ export interface Ref<T = any> {
1213
export default function withRef<OriginalProps>() {
1314
return function addForwardRef<C>(
1415
WrappedComponent: ReactComponent<OriginalProps & Ref> & C,
15-
): React.ComponentClass<OriginalProps> {
16+
): React.ComponentType<OriginalProps> &
17+
NonReactStatics<typeof WrappedComponent> {
1618
class WithRef extends React.Component<OriginalProps, never> {
1719
render() {
1820
return (
1921
<Consumer>
2022
{(ctx) => (
21-
<WrappedComponent {...this.props} ref={ctx.forwardedRef} />
23+
<WrappedComponent {...this.props as any} ref={ctx.forwardedRef} />
2224
)}
2325
</Consumer>
2426
);
@@ -28,8 +30,8 @@ export default function withRef<OriginalProps>() {
2830
const FinalComponent = hoistStatics(
2931
WithRef,
3032
WrappedComponent as React.ComponentClass<any>,
31-
);
33+
) as any;
3234

33-
return FinalComponent as React.ComponentClass<OriginalProps> & C;
35+
return FinalComponent;
3436
};
3537
}

src/utilities/react-compose.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import {ReactComponent} from '@shopify/react-utilities/types';
33
import reactCompose from '@shopify/react-compose';
4+
import {NonReactStatics} from '@shopify/useful-types';
45
// eslint-disable-next-line shopify/strict-component-boundaries
56
import {Provider as RefProvider} from '../components/WithRef';
67

@@ -15,19 +16,18 @@ export default function compose<Props>(
1516
) {
1617
return function wrapComponent<ComposedProps, C>(
1718
OriginalComponent: ReactComponent<ComposedProps> & C,
18-
): ReactComponent<Props> & C {
19+
): ReactComponent<Props> & NonReactStatics<typeof OriginalComponent> {
1920
const Result = reactCompose(...wrappingFunctions)(
2021
OriginalComponent,
2122
) as ReactComponent<ComposedProps>;
2223
// eslint-disable-next-line react/display-name
23-
return React.forwardRef<Props>(
24-
(props: Props, ref: React.RefObject<any>) => {
25-
return (
26-
<RefProvider value={{forwardedRef: ref}}>
27-
<Result {...props} />
28-
</RefProvider>
29-
);
30-
},
31-
) as ReactComponent<Props> & C;
24+
return (React.forwardRef<Props>((props: any, ref: React.RefObject<any>) => {
25+
return (
26+
<RefProvider value={{forwardedRef: ref}}>
27+
<Result {...props} />
28+
</RefProvider>
29+
);
30+
}) as unknown) as ReactComponent<Props> &
31+
NonReactStatics<typeof OriginalComponent>;
3232
};
3333
}

0 commit comments

Comments
 (0)