Skip to content
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

Upgrade to TS 2.8 #342

Merged
merged 11 commits into from
Apr 17, 2018
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ src/app/api/types.ts
# This file is automatically generated when running `yarn client/generate-graphql-schema`
graphqlSchema.json


# These files are auto-generated by `typings-for-css-modules-loader`
*.module.scss.d.ts

Expand All @@ -66,3 +65,8 @@ build
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml

# Created by Serverless
.build
.webpack
.serverless
5 changes: 1 addition & 4 deletions clownOverrides/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
"pre-push": "yarn pretest",
"pre-commit": "yarn common-check",
"tslint": "yarn lint-ts"
},
"devDependencies": {
"typescript": "^2.7.2"
}
}
}
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"repository": "https://github.com/hollowverse/hollowverse.git",
"scripts": {
"pretest": "npm-run-all --aggregate-output -s app/graphql/build -p common-check lint",
"pretest": "npm-run-all --aggregate-output -s app/graphql/build -p -c common-check lint",
"test": "yarn jest -- --verbose",
"lint": "run-p -c --aggregate-output lint-css lint-js lint-graphql lint-ts check-ts",
"lint-css": "stylelint --syntax scss 'src/app/**/*.scss'",
Expand All @@ -15,7 +15,7 @@
"lint-ts/tslint/app": "tslint 'src/app/**/*.ts{,x}' --project src/app",
"lint-ts/tslint/root": "tslint '**/*.ts{,x}' --project . --exclude 'node_modules/**/*' --exclude 'src/app/**/*'",
"lint-ts/tslint": "run-p -c --aggregate-output 'lint-ts/tslint/*'",
"lint-ts": "run-p -c --aggregate-output 'lint-ts/*'",
"lint-ts": "tslint 'src/**/*.ts' --project .",
"server/check-ts": "tsc --project ./src --noEmit",
"app/check-ts": "tsc --project ./src/app --noEmit",
"check-ts": "run-p -c --aggregate-output '*/check-ts'",
Expand Down Expand Up @@ -43,11 +43,12 @@
"deploy": "node ./deploy.js",
"pre-push": "yarn pretest",
"pre-commit": "yarn common-check",
"common-check": "run-p -l -c --aggregate-output validate-filenames 'clown check'",
"common-check": "run-p -l -c --aggregate-output validate-filenames 'clown check' check-integrity",
"tslint": "yarn lint-ts",
"jest": "TZ=UTC NODE_ENV=test jest --colors",
"jest": "TZ=UTC NODE_ENV=test jest",
"clown": "clown",
"coverage/report": "codecov"
"coverage/report": "codecov",
"check-integrity": "yarn check --integrity"
},
"license": "Unlicense",
"homepage": "https://github.com/hollowverse/hollowverse#readme",
Expand Down Expand Up @@ -186,7 +187,7 @@
"@babel/preset-react": "^7.0.0-beta.44",
"@babel/preset-stage-3": "^7.0.0-beta.44",
"@hollowverse/clown": "^3.0.0",
"@hollowverse/config": "^13.0.0",
"@hollowverse/config": "^17.0.0",
"@hollowverse/utils": "^6.0.0",
"@hollowverse/validate-filenames": "latest",
"@types/algoliasearch": "^3.24.5",
Expand Down Expand Up @@ -291,7 +292,8 @@
"ts-loader": "^2.3.4",
"ts-node": "^3.2.0",
"tslint": "^5.9.1",
"typescript": "^2.7.2",
"typescript": "^2.8.1",
"typescript-eslint-parser": "^15.0.0",
"typings-for-css-modules-loader": "^1.7.0",
"uglify-es": "^3.3.9",
"uglify-js": "^2.4.16",
Expand Down
23 changes: 17 additions & 6 deletions src/app/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,25 @@ Promise.all([
.then(renderOnDomReady)
.catch(renderOnDomReady);

// Catch unhandled errors and inform the store
window.onerror = (message, source, line, column) => {
window.addEventListener('error', ({ message, filename, lineno, colno }) => {
store.dispatch(
unhandledErrorThrown({
message,
source,
line,
column,
source: filename,
line: lineno,
column: colno,
}),
);
};
});

window.addEventListener(
'unhandledrejection',
// @ts-ignore
({ reason }: PromiseRejectionEvent) => {
store.dispatch(
unhandledErrorThrown({
message: reason,
}),
);
},
);
20 changes: 5 additions & 15 deletions src/app/components/EditorialSummary/EditorialSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,15 @@ import formatDate from 'date-fns/format';

import classes from './EditorialSummary.module.scss';
import { prettifyUrl } from 'helpers/prettifyUrl';
import { EditorialSummaryNodeType } from 'api/types';
import { EditorialSummaryNodeType, NotablePersonQuery } from 'api/types';
import { Quote } from 'components/Quote/Quote';
import { Collapsable } from 'components/Collapsable/Collapsable';

type Node = {
id: string;
parentId: string | null;
text: string | null;
type: EditorialSummaryNodeType;
sourceUrl: string | null;
sourceTitle: string | null;
};
type NotablePerson = NonNullable<NotablePersonQuery['notablePerson']>;

type Props = {
id: string;
author: string;
lastUpdatedOn: string | null;
nodes: Node[];
};
type Props = NonNullable<NotablePerson['editorialSummary']> & { id: string };

type Node = ArrayElement<Props['nodes']>;

const findChildren = (node: Node, nodes: Node[]) => {
return nodes.filter(child => child.parentId === node.id);
Expand Down
8 changes: 6 additions & 2 deletions src/app/components/FbComments/FbComments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ export class FbComments extends React.PureComponent<Props> {
} else if (this.commentsNode) {
this.commentsObserver = new MutationObserver(mutations => {
for (const mutation of mutations) {
const attr = (mutation.target as Element).attributes.getNamedItem(
OBSERVED_FB_ATTR_NAME,
);

if (
mutation.attributeName === OBSERVED_FB_ATTR_NAME &&
mutation.target.attributes.getNamedItem(OBSERVED_FB_ATTR_NAME)
.value === 'rendered'
attr !== null &&
attr.value === 'rendered'
) {
resolve();
if (this.commentsObserver) {
Expand Down
15 changes: 7 additions & 8 deletions src/app/helpers/serverTestHelpers.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createServerRenderMiddleware } from 'createServerRenderMiddleware';
import { agent, Response } from 'supertest';
import { agent } from 'supertest';
import {
defaultTestDependencyOverrides,
createMockGetResponseForDataRequest,
Expand All @@ -18,17 +18,12 @@ type CreateServerSideTestContextOptions = Partial<
mockDataResponsesOverrides?: Partial<ResolvedData>;
};

export type ServerSideTestContext = {
res: Response;
$: CheerioStatic;
};

export const createServerSideTestContext = async ({
path,
routesMap = defaultRoutesMap,
epicDependenciesOverrides = {},
mockDataResponsesOverrides,
}: CreateServerSideTestContextOptions): Promise<ServerSideTestContext> => {
mockDataResponsesOverrides = {},
}: CreateServerSideTestContextOptions) => {
const app = express();
const ssrMiddleware = createServerRenderMiddleware({
epicDependenciesOverrides: {
Expand Down Expand Up @@ -56,3 +51,7 @@ export const createServerSideTestContext = async ({

return { res, $ };
};

export type ServerSideTestContext = UnboxPromise<
ReturnType<typeof createServerSideTestContext>
>;
17 changes: 6 additions & 11 deletions src/app/helpers/testHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
createConfiguredStore,
} from 'store/createConfiguredStore';
import createMemoryHistory from 'history/createMemoryHistory';
import { mount, ReactWrapper } from 'enzyme';
import { mount } from 'enzyme';
import { delay } from 'helpers/delay';
import { once } from 'lodash';
import { AppRoutesMap, App } from 'components/App/App';
Expand Down Expand Up @@ -96,13 +96,6 @@ export const createTestTree = ({
</HelmetProvider>
);

export type ClientSideTestContext = {
store: Store<StoreState>;
history: History;
wrapper: ReactWrapper<any>;
dependencies: EpicDependencies;
};

export type CreateClientSideTestContextOptions = Partial<{
epicDependenciesOverrides: Partial<EpicDependencies>;
createHistoryOptions: MemoryHistoryBuildOptions;
Expand All @@ -124,9 +117,7 @@ export const createClientSideTestContext = async ({
createHistoryOptions = { initialEntries: ['/'] },
mockDataResponsesOverrides = {},
...rest
}: Partial<CreateClientSideTestContextOptions> = {}): Promise<
ClientSideTestContext
> => {
}: Partial<CreateClientSideTestContextOptions> = {}) => {
const { store, dependencies, history } = createConfiguredStore({
epicDependenciesOverrides: {
...defaultTestDependencyOverrides,
Expand Down Expand Up @@ -158,3 +149,7 @@ export const createClientSideTestContext = async ({

return { wrapper, store, history, dependencies };
};

export type ClientSideTestContext = UnboxPromise<
ReturnType<typeof createClientSideTestContext>
>;
18 changes: 10 additions & 8 deletions src/app/pages/NotablePerson/NotablePerson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const Page = withRouter(
return apiClient.request<NotablePersonQuery>(query, { slug });
};

renderRelatedPeople = (notablePerson: NotablePersonType) => {
const { relatedPeople } = notablePerson!; // tslint:disable-line:no-non-null-assertion
renderRelatedPeople = (notablePerson: NonNullable<NotablePersonType>) => {
const { relatedPeople } = notablePerson;

return relatedPeople.length ? (
<div className={classes.relatedPeople}>
Expand All @@ -61,8 +61,8 @@ const Page = withRouter(
) : null;
};

renderFbComments = (notablePerson: NotablePersonType) => {
const { commentsUrl } = notablePerson!; // tslint:disable-line:no-non-null-assertion
renderFbComments = (notablePerson: NonNullable<NotablePersonType>) => {
const { commentsUrl } = notablePerson;

return (
<OptionalIntersectionObserver rootMargin="0% 0% 25% 0%" triggerOnce>
Expand All @@ -77,8 +77,10 @@ const Page = withRouter(
);
};

renderEditorialSummary = (notablePerson: NotablePersonType) => {
const { editorialSummary, slug, name } = notablePerson!; // tslint:disable-line:no-non-null-assertion
renderEditorialSummary = (
notablePerson: NonNullable<NotablePersonType>,
) => {
const { editorialSummary, slug, name } = notablePerson;

return editorialSummary ? (
<Card className={cc([classes.card, classes.editorialSummary])}>
Expand Down Expand Up @@ -111,8 +113,8 @@ const Page = withRouter(
</>
);

render200Status = (notablePerson: NotablePersonType) => {
const { slug, name, commentsUrl } = notablePerson!; // tslint:disable-line:no-non-null-assertion
render200Status = (notablePerson: NonNullable<NotablePersonType>) => {
const { slug, name, commentsUrl } = notablePerson;
const isWhitelisted = isWhitelistedPage(`/${slug}`);

return (
Expand Down
5 changes: 1 addition & 4 deletions src/app/pages/NotablePerson/NotablePersonBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import { NotablePersonBodyDummyData } from './NotablePersonBodyDummyData';
import classes from './NotablePersonBody.module.scss';

type Props = {
notablePerson?: NotablePersonQuery['notablePerson'];
notablePerson?: NonNullable<NotablePersonQuery['notablePerson']>;
editorialSummary?: JSX.Element;
};

export class NotablePersonBody extends React.PureComponent<Props> {
render() {
const { notablePerson, editorialSummary } = this.props;
if (notablePerson === null) {
return null;
}

const { name, mainPhoto, summary } =
notablePerson === undefined ? NotablePersonBodyDummyData : notablePerson;
Expand Down
1 change: 1 addition & 0 deletions src/app/store/features/analytics/epic.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable no-unnecessary-type-assertion
import { LOCATION_CHANGE } from 'react-router-redux';

import { Action, StoreState } from 'store/types';
Expand Down
1 change: 1 addition & 0 deletions src/app/store/features/asyncData/epic.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable no-unnecessary-type-assertion
import { setResolvedData } from './actions';

import { Action, StoreState, SetResolvedDataPayload } from 'store/types';
Expand Down
2 changes: 2 additions & 0 deletions src/app/store/features/logging/epic.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// tslint:disable no-unnecessary-type-assertion

import { Action, StoreState } from 'store/types';

import { Epic } from 'redux-observable';
Expand Down
4 changes: 0 additions & 4 deletions src/app/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ export type ActionTypeToPayloadType = {
from: string;
to: string;
};
NOTABLE_PERSON_VISITED_THROUGH_SEARCH: {
notablePerson: string | null;
searchQuery: string;
};
/** Value is the path to the selected page */
SEARCH_RESULT_SELECTED: string;
SET_ALTERNATIVE_SEARCH_BOX_TEXT: string | null;
Expand Down
3 changes: 3 additions & 0 deletions src/app/typings/typeHelpers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type UnboxPromise<T> = T extends Promise<infer R> ? R : T;

type ArrayElement<T extends any[]> = T extends Array<infer R> ? R : never;
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,9 @@
lodash "^4.17.4"
sort-keys "^2.0.0"

"@hollowverse/config@^13.0.0":
version "13.0.0"
resolved "https://registry.yarnpkg.com/@hollowverse/config/-/config-13.0.0.tgz#cdeb0d171e2132a4eba37ab14cf7b13d7d485bde"
"@hollowverse/config@^17.0.0":
version "17.0.0"
resolved "https://registry.yarnpkg.com/@hollowverse/config/-/config-17.0.0.tgz#26cf5e6015aa3e58e0a3cf8eafa33581b26291d1"
dependencies:
"@babel/core" "7.0.0-beta.44"
"@babel/plugin-proposal-object-rest-spread" "^7.0.0-beta.44"
Expand All @@ -718,7 +718,7 @@
tslint-eslint-rules "^5.0.0"
tslint-microsoft-contrib "^5.0.3"
tslint-react "^3.5.1"
typescript-eslint-parser "^14.0.0"
typescript-eslint-parser "^15.0.0"

"@hollowverse/utils@^6.0.0":
version "6.0.0"
Expand Down Expand Up @@ -12650,16 +12650,16 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript-eslint-parser@^14.0.0:
version "14.0.0"
resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-14.0.0.tgz#c90a8f541c1d96e5c55e2807c61d154e788520f9"
typescript-eslint-parser@^15.0.0:
version "15.0.0"
resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-15.0.0.tgz#882fd3d7aabffbab0a7f98d2a59fb9a989c2b37f"
dependencies:
lodash.unescape "4.0.1"
semver "5.5.0"

typescript@^2.7.2:
version "2.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836"
typescript@^2.8.1:
version "2.8.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.1.tgz#6160e4f8f195d5ba81d4876f9c0cc1fbc0820624"

typings-for-css-modules-loader@^1.7.0:
version "1.7.0"
Expand Down