Skip to content

Commit

Permalink
fix: fix types for TypeScript 3.8 (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen authored Nov 18, 2021
1 parent 1afd218 commit 54fad92
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 192 deletions.
1 change: 1 addition & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/docs/**",
"!**/node_modules/**"
],
"coverageReporters": [
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"format:test": "prettier --write 'test/**/*.{js,jsx,ts,tsx}'",
"format": "yarn format:src && yarn format:test",
"jest": "jest -c jest.config.json",
"test:types": "echo 'Need to fix types' # tsc --skipLibCheck --noEmit",
"test:types": "tsc --skipLibCheck --noEmit",
"test:unit": "yarn jest",
"test": "yarn test:types && yarn test:unit",
"prepublishOnly": "npm run build",
Expand Down Expand Up @@ -63,7 +63,7 @@
"rollup-plugin-typescript2": "^0.19.3",
"simple-git-hooks": "^2.7.0",
"standard-version": "^9.3.2",
"typescript": "^3.4.5"
"typescript": "^3.8.0"
},
"gh-pages-deploy": {
"staticpath": "demo/dist/"
Expand Down
14 changes: 7 additions & 7 deletions src/Context.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import * as React from "react";
import { chartDefaultProps } from "./default-props";

import { ReactGoogleChartPropsWithDefaults } from "./types";
import { ReactGoogleChartProps } from "./types";
const { Provider, Consumer } = React.createContext(chartDefaultProps);

export const ContextProvider = ({
children,
value
value,
}: {
children: any;
value: ReactGoogleChartPropsWithDefaults;
value: ReactGoogleChartProps;
}) => {
return <Provider value={value}>{children}</Provider>;
};

export const ContextConsumer = ({
render
render,
}: {
render: ((context: ReactGoogleChartPropsWithDefaults) => JSX.Element | null);
render: (context: ReactGoogleChartProps) => JSX.Element | null;
}) => {
return (
<Consumer>
{context => {
return render(context as ReactGoogleChartPropsWithDefaults);
{(context) => {
return render(context as ReactGoogleChartProps);
}}
</Consumer>
);
Expand Down
23 changes: 11 additions & 12 deletions src/ReactGoogleCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
GoogleViz,
ReactGoogleChartProps,
ReactGoogleChartState,
ReactGoogleChartPropsWithDefaults
} from "./types";
import { chartDefaultProps } from "./default-props";
import { GoogleChartLoader } from "./components/GoogleChartLoader";
Expand All @@ -15,12 +14,11 @@ export class Chart extends React.Component<
ReactGoogleChartProps,
ReactGoogleChartState
> {

_isMounted = false;

state = {
loadingStatus: "loading" as ReactGoogleChartState["loadingStatus"],
google: null as ReactGoogleChartState["google"]
google: null as ReactGoogleChartState["google"],
};

static defaultProps = chartDefaultProps;
Expand All @@ -32,13 +30,13 @@ export class Chart extends React.Component<
chartVersion,
mapsApiKey,
loader,
errorElement
errorElement,
} = this.props;
return (
<ContextProvider value={this.props as ReactGoogleChartPropsWithDefaults}>
<ContextProvider value={this.props as ReactGoogleChartProps}>
{this.state.loadingStatus === "ready" && this.state.google !== null ? (
<GoogleChart
{...this.props as ReactGoogleChartPropsWithDefaults}
{...(this.props as ReactGoogleChartProps)}
google={this.state.google}
/>
) : this.state.loadingStatus === "errored" && errorElement ? (
Expand Down Expand Up @@ -69,9 +67,11 @@ export class Chart extends React.Component<
} else {
// IE11: window.google is not fully set, we have to wait
const id = setInterval(() => {
const google = (window as Window & {
google?: GoogleViz;
}).google;
const google = (
window as Window & {
google?: GoogleViz;
}
).google;

if (this._isMounted) {
if (google && this.isFullyLoaded(google)) {
Expand All @@ -81,21 +81,20 @@ export class Chart extends React.Component<
} else {
clearInterval(id);
}

}, 1000);
}
};

onSuccess = (google: GoogleViz) => {
this.setState({
loadingStatus: "ready",
google
google,
});
};

onError = () => {
this.setState({
loadingStatus: "errored"
loadingStatus: "errored",
});
};

Expand Down
Loading

0 comments on commit 54fad92

Please sign in to comment.