Skip to content

Commit

Permalink
Upgrade TypeScript to 3.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
toolness committed Feb 15, 2019
1 parent 5b63bed commit 62320c0
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 19 deletions.
4 changes: 3 additions & 1 deletion frontend/lib/app-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ export const AppContext = React.createContext<AppContextType>(defaultContext);
*/
export function withAppContext<P extends AppContextType>(Component: React.ComponentType<P>): React.ComponentType<Omit<P, keyof AppContextType>> {
return function(props: Omit<P, keyof AppContextType>) {
// https://github.com/Microsoft/TypeScript/issues/28748
const tsIssue28748Workaround = props as any;
return (
<AppContext.Consumer>
{(context) => <Component {...props} {...context} />}
{(context) => <Component {...tsIssue28748Workaround} {...context} />}
</AppContext.Consumer>
);
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/lib/aria.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ export const AriaContext = React.createContext<AriaContextType>({

function withAriaContext<P extends AriaContextType>(Component: React.ComponentType<P>): React.ComponentType<Omit<P, keyof AriaContextType>> {
return function(props: Omit<P, keyof AriaContextType>) {
// https://github.com/Microsoft/TypeScript/issues/28748
const tsIssue28748Workaround = props as any;
return (
<AriaContext.Consumer>
{(context) => <Component {...props} announce={context.announce} />}
{(context) => <Component {...tsIssue28748Workaround} announce={context.announce} />}
</AriaContext.Consumer>
);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/faceboox-pixel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ declare global {
*/
export const fbq: FacebookPixelAPI = function fbq() {
if (typeof(window) !== 'undefined' && typeof(window.fbq) === 'function') {
window.fbq.apply(window, arguments);
window.fbq.apply(window, arguments as any);
}
};
10 changes: 7 additions & 3 deletions frontend/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ export function dynamicallyImportFetch(): Promise<typeof fetch> {
* Just like window.fetch(), but dynamically loads a polyfill
* if needed.
*/
export const awesomeFetch: typeof fetch = function(this: any) {
export const awesomeFetch: typeof fetch = function(
this: any,
input: RequestInfo,
init?: RequestInit | undefined
): Promise<Response> {
if (typeof(fetch) === 'function') {
return fetch.apply(this, arguments);
return fetch.apply(this, [input, init]);
}
return dynamicallyImportFetch().then(fetch => {
return fetch.apply(this, arguments);
return fetch.apply(this, [input, init]);
});
};

Expand Down
7 changes: 6 additions & 1 deletion frontend/lib/google-analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ function callAnyHitCallbacks(args: unknown[]) {
*/
export const ga: GoogleAnalyticsAPI = function ga() {
if (typeof(window) !== 'undefined' && typeof(window.ga) === 'function') {
window.ga.apply(window, arguments);
// We're typecasting arguments as "any" here because as of TS 3.2,
// apply() can't fully model functions that have overloads, which is what
// ga() is. However, the fact that we're returning an object that's
// strongly typed means that type safety is still ensured where it matters
// most.
window.ga.apply(window, arguments as any);
} else {
callAnyHitCallbacks(Array.from(arguments));
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/loading-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class LoadingOverlayManagerWithoutRouter extends React.Component<LoadingOverlayM
if (div && this.state.latestSnapshot) {
div.innerHTML = '';
div.appendChild(this.state.latestSnapshot.div);
window.scroll({ top: this.state.latestSnapshot.scroll, left: 0, behavior: 'instant' });
window.scroll({ top: this.state.latestSnapshot.scroll, left: 0, behavior: 'auto' });
}
} else if (prevState.showOverlay === true && this.state.showOverlay === false) {
// We just stopped showing the overlay, so make sure the top of the page
Expand Down
4 changes: 2 additions & 2 deletions frontend/lib/progress-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import autobind from "autobind-decorator";
import { RouteComponentProps, withRouter, Route, Switch } from 'react-router';
import { RouteComponentProps, withRouter, Route, RouteProps, Switch } from 'react-router';
import { CSSTransition } from 'react-transition-group';
import { TransitionContextGroup } from './transition-context';
import classnames from 'classnames';
Expand Down Expand Up @@ -181,7 +181,7 @@ class RouteProgressBarWithoutRouter extends React.Component<RouteProgressBarProp
<CSSTransition key={currStep} classNames="jf-progress-step"
timeout={JF_PROGRESS_TRANSITION_MS} enter={isTransitionEnabled} exit={isTransitionEnabled}>
<Switch location={location}>
{props.steps.map(step => <Route key={step.path} {...step} />)}
{props.steps.map(step => <Route<RouteProps> key={step.path} {...step} />)}
</Switch>
</CSSTransition>
</TransitionContextGroup>
Expand Down
4 changes: 2 additions & 2 deletions frontend/lib/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const originalLog = console.log;
* Combined with the general sluggishness of Jest on Windows, I'm
* very much regretting not using Mocha at this point.
*/
console.log = function() {
originalLog.apply(this, arguments);
console.log = function(message?: any, ...optionalParams: any[]) {
originalLog.apply(this, [message, ...optionalParams]);
originalLog.call(this, chalk.green('\n ^^^ SOMETHING GOT LOGGED! ^^^\n'));
};

Expand Down
4 changes: 3 additions & 1 deletion frontend/lib/transition-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ export function TransitionContextGroup(props: TransitionContextGroupProps): JSX.
*/
export function withTransitionContext<P extends TransitionContextType>(Component: React.ComponentType<P>): React.ComponentType<Omit<P, keyof TransitionContextType>> {
return function(props: Omit<P, keyof TransitionContextType>) {
// https://github.com/Microsoft/TypeScript/issues/28748
const tsIssue28748Workaround = props as any;
return (
<TransitionContext.Consumer>
{(context) => <Component {...props} {...context} />}
{(context) => <Component {...tsIssue28748Workaround} {...context} />}
</TransitionContext.Consumer>
);
}
Expand Down
15 changes: 10 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"smoothscroll-polyfill": "0.4.3",
"source-map-support": "0.5.9",
"ts-loader": "4.5.0",
"typescript": "3.1.6",
"typescript": "3.3.1",
"uglify-js": "3.4.9",
"webpack": "4.23.1",
"webpack-cli": "3.1.2",
Expand Down

0 comments on commit 62320c0

Please sign in to comment.