Skip to content

Updating to typescript 3.2 #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"allowBlockStart": false
}
],
"import/named": "off",
"import/no-named-as-default": "off",
"react/button-has-type": "off",
"react/no-array-index-key": "off",
Expand Down
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Update most devDependencies ([#1327](https://github.com/Shopify/polaris-react/pull/1327))
- Bump react-utilites to remove a transitive dependency on core-js. ([#1343](https://github.com/Shopify/polaris-react/pull/1343))
- Updated App Bridge to version 1.3.0 ([#1349](https://github.com/Shopify/polaris-react/pull/1349))
- Updated typescript to 3.2.4 ([#1388](https://github.com/Shopify/polaris-react/pull/1388))

### Code quality

Expand Down
5 changes: 0 additions & 5 deletions config/typescript/prop-types.d.ts

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@
"shelljs": "^0.8.3",
"shx": "^0.3.2",
"svgo": "^1.2.2",
"typescript": "~3.1.6",
"typescript": "~3.2.4",
"yargs": "^13.2.2"
},
"peerDependencies": {
"react": "^16.3.1",
"react-dom": "^16.3.1"
},
"resolutions": {
"typescript-eslint-parser": "20.0.0"
"typescript-eslint-parser": "22.0.0"
},
"files": [
"esnext",
Expand All @@ -182,9 +182,9 @@
"@shopify/javascript-utilities": "^2.2.1",
"@shopify/polaris-icons": "^3.3.0",
"@shopify/polaris-tokens": "^2.5.0",
"@shopify/react-compose": "^0.1.6",
"@shopify/react-compose": "^1.0.0",
"@shopify/react-utilities": "^2.0.4",
"@types/prop-types": "^15.5.5",
"@shopify/useful-types": "^1.2.4",
"@types/react": "^16.4.7",
"@types/react-dom": "^16.0.6",
"@types/react-transition-group": "^2.0.7",
Expand Down
4 changes: 3 additions & 1 deletion src/components/ActionList/ActionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export default function ActionList({
}

const hasMultipleSections = finalSections.length > 1;
const Element: string = hasMultipleSections ? 'ul' : 'div';
// Type asserting to any is required for TS3.2 but can be removed when we update to 3.3
// see https://github.com/Microsoft/TypeScript/issues/28768
const Element: any = hasMultipleSections ? 'ul' : 'div';
const sectionMarkup = finalSections.map((section, index) => {
return (
<Section
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppProvider/tests/AppProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('<AppProvider />', () => {
}
}

const wrapper = TestUtils.renderIntoDocument(
const wrapper: unknown = TestUtils.renderIntoDocument(
<AppProvider i18n={i18n} linkComponent={CustomLinkComponent}>
<Child />
</AppProvider>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export default function withAppProvider<OwnProps>() {
);
}

return <WrappedComponent {...this.props} polaris={polarisContext} />;
return (
<WrappedComponent {...this.props as any} polaris={polarisContext} />
);
}

private handleContextUpdate = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export default function withSticky() {

render() {
return (
<WrappedComponent {...this.props} polaris={this.polarisContext} />
<WrappedComponent
{...this.props as any}
polaris={this.polarisContext}
/>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ChoiceList/ChoiceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function ChoiceList({
error,
name = getUniqueID(),
}: CombinedProps) {
const ControlComponent: typeof Checkbox | typeof RadioButton = allowMultiple
? Checkbox
: RadioButton;
// Type asserting to any is required for TS3.2 but can be removed when we update to 3.3
// see https://github.com/Microsoft/TypeScript/issues/28768
const ControlComponent: any = allowMultiple ? Checkbox : RadioButton;

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

Expand Down
2 changes: 1 addition & 1 deletion src/components/Connected/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface State {

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

const leftConnectionMarkup = left ? (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function Icon({
const defaultIconProps = {
className: styles.Svg,
focusable: 'false',
'aria-hidden': 'true',
'aria-hidden': 'true' as 'true',
};

if (untrusted) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class Popover extends React.PureComponent<Props, State> {

render() {
const {
activatorWrapper: WrapperComponent = 'div',
activatorWrapper: WrapperComponent = 'div' as any,
children,
onClose,
activator,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ThemeProvider/tests/ThemeProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('<ThemeProvider />', () => {
}
}

const wrapper = TestUtils.renderIntoDocument(
const wrapper: unknown = TestUtils.renderIntoDocument(
<ThemeProvider
theme={{
logo: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class Tooltip extends React.PureComponent<Props, State> {
content,
light,
preferredPosition = 'below',
activatorWrapper: WrapperComponent = 'span',
activatorWrapper: WrapperComponent = 'span' as any,
} = this.props;

const {active, activatorNode} = this.state;
Expand Down
10 changes: 6 additions & 4 deletions src/components/WithRef/WithRef.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import hoistStatics from 'hoist-non-react-statics';
import {ReactComponent} from '@shopify/react-utilities/types';
import {NonReactStatics} from '@shopify/useful-types';
import {Consumer} from './components';

export type ComponentType<P> = React.ComponentClass<P> | React.SFC<P>;
Expand All @@ -12,13 +13,14 @@ export interface Ref<T = any> {
export default function withRef<OriginalProps>() {
return function addForwardRef<C>(
WrappedComponent: ReactComponent<OriginalProps & Ref> & C,
): React.ComponentClass<OriginalProps> {
): React.ComponentType<OriginalProps> &
NonReactStatics<typeof WrappedComponent> {
class WithRef extends React.Component<OriginalProps, never> {
render() {
return (
<Consumer>
{(ctx) => (
<WrappedComponent {...this.props} ref={ctx.forwardedRef} />
<WrappedComponent {...this.props as any} ref={ctx.forwardedRef} />
)}
</Consumer>
);
Expand All @@ -28,8 +30,8 @@ export default function withRef<OriginalProps>() {
const FinalComponent = hoistStatics(
WithRef,
WrappedComponent as React.ComponentClass<any>,
);
) as any;

return FinalComponent as React.ComponentClass<OriginalProps> & C;
return FinalComponent;
};
}
20 changes: 10 additions & 10 deletions src/utilities/react-compose.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import {ReactComponent} from '@shopify/react-utilities/types';
import reactCompose from '@shopify/react-compose';
import {NonReactStatics} from '@shopify/useful-types';
// eslint-disable-next-line shopify/strict-component-boundaries
import {Provider as RefProvider} from '../components/WithRef';

Expand All @@ -15,19 +16,18 @@ export default function compose<Props>(
) {
return function wrapComponent<ComposedProps, C>(
OriginalComponent: ReactComponent<ComposedProps> & C,
): ReactComponent<Props> & C {
): ReactComponent<Props> & NonReactStatics<typeof OriginalComponent> {
const Result = reactCompose(...wrappingFunctions)(
OriginalComponent,
) as ReactComponent<ComposedProps>;
// eslint-disable-next-line react/display-name
return React.forwardRef<Props>(
(props: Props, ref: React.RefObject<any>) => {
return (
<RefProvider value={{forwardedRef: ref}}>
<Result {...props} />
</RefProvider>
);
},
) as ReactComponent<Props> & C;
return (React.forwardRef<Props>((props: any, ref: React.RefObject<any>) => {
return (
<RefProvider value={{forwardedRef: ref}}>
<Result {...props} />
</RefProvider>
);
}) as unknown) as ReactComponent<Props> &
NonReactStatics<typeof OriginalComponent>;
};
}
Loading