Skip to content
This repository was archived by the owner on Dec 9, 2021. It is now read-only.

Commit 74e9d25

Browse files
committed
Update types
1 parent c24be1b commit 74e9d25

16 files changed

+106
-53
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"rimraf": "2.6.1",
9292
"robotstxt-webpack-plugin": "2.0.0",
9393
"style-loader": "0.18.2",
94+
"tslib": "1.7.1",
9495
"typescript": "2.4.2",
9596
"webpack-dev-middleware": "1.11.0",
9697
"webpack-hot-middleware": "2.18.2"

src/RouterWrapper.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface IProviderWrapperProps {
1717
context?: any;
1818
}
1919

20-
const RouterWrapper: React.StatelessComponent<IStore> = (props: IProviderWrapperProps): JSX.Element => {
20+
const RouterWrapper: React.StatelessComponent<IProviderWrapperProps> = (props: IProviderWrapperProps): JSX.Element => {
2121
const Router = props.isServerSide ? StaticRouter : BrowserRouter;
2222

2323
return (

src/client.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const store: ISagaStore<IStore> = ProviderService.createProviderStore(initialSt
2020

2121
delete (window as any)['__STATE__'];
2222

23-
const render = (Component: React.StatelessComponent) =>
23+
const render = (Component: any) =>
2424
ReactDOM.render(
2525
<AppContainer>
2626
<Component store={store} />

src/interfaces/IContactForm.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
interface IContactForm {
2+
name: string;
3+
email: string;
4+
message: string;
5+
exampleSelect1: string;
6+
codeQualityRadio: string;
7+
starred: string;
8+
}
9+
10+
export default IContactForm;

src/interfaces/IController.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as hapi from 'hapi';
1+
import * as Hapi from 'hapi';
22

33
interface IController {
4-
mapRoutes(server: hapi.Server): void;
4+
mapRoutes(server: Hapi.Server): void;
55
}
66

77
export default IController;

src/server/controllers/AssetsController.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import * as path from 'path';
22
import * as Hapi from 'hapi';
33
import IController from '../../interfaces/IController';
44

@@ -8,7 +8,7 @@ class AssetsController implements IController{
88
server.route({
99
method: 'GET',
1010
path: '/assets/{file*}',
11-
handler: (request: hapi.Request, reply: hapi.ReplyNoContinue) => {
11+
handler: (request: Hapi.Request, reply: Hapi.ReplyNoContinue) => {
1212
reply.file(path.resolve(__dirname, `../../public${request.path}`));
1313
},
1414
});

src/server/controllers/ReactController.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {renderToString} from 'react-dom/server';
2-
import path from 'path';
2+
import * as path from 'path';
33
import * as fse from 'fs-extra';
44
import * as React from 'react';
55
import RouterWrapper from '../../RouterWrapper';
@@ -16,7 +16,7 @@ class ReactController implements IController {
1616
server.route({
1717
method: 'GET',
1818
path: '/{route*}',
19-
handler: async (request: hapi.Request, reply: hapi.ReplyNoContinue): Promise<void> => {
19+
handler: async (request: Hapi.Request, reply: Hapi.ReplyNoContinue): Promise<void> => {
2020
const store: ISagaStore<IStore> = ProviderService.createProviderStore({}, true);
2121
const context: any = {};
2222
const app = (

src/server/plugin/HapiWebpackHotPlugin.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import Webpack from 'webpack';
2-
import ServerManager from '../ServerManager';
3-
import HapiWebpackPlugin from 'hapi-webpack-plugin';
4-
import notifier from 'node-notifier';
1+
import * as Webpack from 'webpack';
2+
import * as HapiWebpackPlugin from 'hapi-webpack-plugin';
3+
import * as notifier from 'node-notifier';
54
import * as Hapi from 'hapi';
5+
import ServerManager from '../ServerManager';
66

77
class HapiWebpackHotPlugin {
88

99
constructor(server: Hapi.Server) {
10-
const compiler = new Webpack(require('../../../webpack.config.js'));
10+
const compiler: any = new Webpack(require('../../../webpack.config.js'));
1111

12-
compiler.plugin('done', (stats) => this._onDone(stats));
12+
compiler.plugin('done', (stats: any) => this._onDone(stats));
1313

1414
const options = {
1515
assets: {
@@ -32,7 +32,7 @@ class HapiWebpackHotPlugin {
3232
});
3333
}
3434

35-
private _onDone(stats): void {
35+
private _onDone(stats: any): void {
3636
const pkg = require('../../../package.json');
3737
const time = ((stats.endTime - stats.startTime) / 1000).toFixed(2);
3838

@@ -44,7 +44,7 @@ class HapiWebpackHotPlugin {
4444
title: pkg.name,
4545
message: `WebPack is done!\n${stats.compilation.errors.length} errors in ${time}s`,
4646
timeout: 1,
47-
});
47+
} as any);
4848
}
4949

5050
}

src/services/ServerService.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
import * as Hapi from 'hapi';
2+
13
class ServerService {
24

3-
public static createLocationObject(request) {
4-
const protocal = request.headers['x-forwarded-proto'] || request.connection.info.protocol;
5+
public static createLocationObject(request: Hapi.Request): any {
6+
const protocol: string = request.headers['x-forwarded-proto'] || request.connection.info.protocol;
57

68
return {
79
...request.url,
810
host: request.info.host,
911
hostname: request.info.host.split(':')[0],
10-
href: `${protocal}://${request.info.host}${request.url.path}`,
11-
origin: `${protocal}://${request.info.host}`,
12+
href: `${protocol}://${request.info.host}${request.url.path}`,
13+
origin: `${protocol}://${request.info.host}`,
1214
pathname: request.url.path.split('?')[0],
13-
protocal: `${protocal}:`,
15+
protocol: `${protocol}:`,
1416
};
1517
}
1618

src/store/user/UserSaga.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import {put} from 'redux-saga/effects';
22
import UserAction from './UserAction';
33
import LoadingAction from '../loading/LoadingAction';
4+
import IAction from '../../interfaces/IAction';
45

56
class UserSaga {
67

7-
static* loadUser(action) {
8+
static* loadUser(action: IAction<void> = null) {
89
yield put({
910
type: LoadingAction.SET_LOADING,
1011
payload: true,

src/views/About.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import {connect} from 'react-redux';
33
import MetaAction from '../store/meta/MetaAction';
44
import IStore from '../interfaces/IStore';
55
import {Dispatch} from "redux";
6+
import IMetaReducerState from '../interfaces/reducers/IMetaReducerState';
67

78
const mapStateToProps = (state: IStore) => ({});
89

910
const mapDispatchToProps = (dispatch: Dispatch<any>) => ({
10-
setMeta: (meta) => dispatch(MetaAction.setMeta(meta)),
11+
setMeta: (meta: IMetaReducerState) => dispatch(MetaAction.setMeta(meta)),
1112
});
1213

1314
class About extends React.Component<any, void> {

src/views/Contact.tsx

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import * as React from 'react';
22
import {connect} from 'react-redux';
33
import MetaAction from '../store/meta/MetaAction';
4-
import {Field, FormProps, reduxForm} from 'redux-form';
4+
import {reduxForm, Field, FormProps, FormErrors} from 'redux-form';
55
import IStore from '../interfaces/IStore';
66
import {Dispatch} from 'redux';
7+
import IContactForm from '../interfaces/IContactForm';
8+
import IMetaReducerState from '../interfaces/reducers/IMetaReducerState';
79

810
const mapStateToProps = (state: IStore) => ({});
911

1012
const mapDispatchToProps = (dispatch: Dispatch<any>) => ({
11-
setMeta: (meta) => dispatch(MetaAction.setMeta(meta)),
13+
setMeta: (meta: IMetaReducerState) => dispatch(MetaAction.setMeta(meta)),
1214
});
1315

14-
interface IContactProps extends FormProp {
16+
interface IContactProps extends FormProps {
1517
}
1618

17-
class Contact extends React.Component<IContactProps, void> {
19+
class Contact extends React.Component {
1820

19-
_handleSubmitHandler = (formData) => this._onFormSubmit(formData);
21+
private _handleSubmitHandler: Function = (formData: IContactForm) => this._onFormSubmit(formData);
2022

2123
componentWillMount(): void {
2224
this.props.setMeta({title: 'Contact Page'});
@@ -121,13 +123,13 @@ class Contact extends React.Component<IContactProps, void> {
121123
);
122124
}
123125

124-
_onFormSubmit(formData) {
126+
private _onFormSubmit(formData: IContactForm): void {
125127
console.info(formData);
126128

127129
window.alert(JSON.stringify(formData, null, 2));
128130
}
129131

130-
_renderInputField(field) {
132+
private _renderInputField(field: any): JSX.Element {
131133
const {meta: {touched, error}} = field;
132134
const className = `small text-danger ${touched && error ? '' : 'd-none'}`;
133135

@@ -147,7 +149,7 @@ class Contact extends React.Component<IContactProps, void> {
147149
);
148150
}
149151

150-
_renderCheckbox(field) {
152+
private _renderCheckbox(field: any): JSX.Element {
151153
return (
152154
<label
153155
className="form-check-label"
@@ -163,7 +165,7 @@ class Contact extends React.Component<IContactProps, void> {
163165
);
164166
}
165167

166-
_renderRadio(field) {
168+
private _renderRadio(field: any): JSX.Element {
167169
return (
168170
<div className="form-check">
169171
<label htmlFor={field.input.name} className="form-check-label">
@@ -183,7 +185,7 @@ class Contact extends React.Component<IContactProps, void> {
183185
);
184186
}
185187

186-
_renderTextArea(field) {
188+
private _renderTextArea(field: any): JSX.Element {
187189
const {meta: {touched, error}} = field;
188190
const className = `small text-danger ${touched && error ? '' : 'd-none'}`;
189191

@@ -203,7 +205,7 @@ class Contact extends React.Component<IContactProps, void> {
203205
}
204206

205207
/* eslint-disable jsx-a11y/label-has-for */
206-
_renderSelect(field) {
208+
private _renderSelect(field: any): JSX.Element {
207209
return (
208210
<div>
209211
<label htmlFor={field.name}>
@@ -228,9 +230,9 @@ class Contact extends React.Component<IContactProps, void> {
228230

229231
export default reduxForm({
230232
form: 'contactForm',
231-
validate: (formData) => {
232-
const errors = {};
233-
const validEmailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
233+
validate: (formData: Readonly<IContactForm>) => {
234+
const errors: FormErrors<IContactForm> = {};
235+
const validEmailRegex: RegExp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
234236

235237
if (!validEmailRegex.test(formData.email)) {
236238
errors.email = 'Invalid email address';

src/views/Home.tsx

+15-8
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,29 @@ import {Dispatch} from 'redux';
77
import IMetaReducerState from '../interfaces/reducers/IMetaReducerState';
88
import IUserReducerState from '../interfaces/reducers/IUserReducerState';
99

10-
const mapStateToProps = (state: IStore) => ({
10+
interface IStateToProps {
11+
readonly user: IUserReducerState;
12+
}
13+
14+
interface IDispatchToProps {
15+
loadUser: () => void;
16+
setMeta: (meta: IMetaReducerState) => void;
17+
}
18+
19+
const mapStateToProps = (state: IStore): IStateToProps => ({
1120
user: state.userReducer,
1221
});
1322

14-
const mapDispatchToProps = (dispatch: Dispatch<any>) => ({
23+
const mapDispatchToProps = (dispatch: Dispatch<any>): IDispatchToProps => ({
1524
loadUser: () => dispatch(UserAction.loadUser()),
1625
setMeta: (meta: IMetaReducerState) => dispatch(MetaAction.setMeta(meta)),
1726
});
1827

19-
interface IHomeProps {
20-
readonly user: IUserReducerState;
21-
loadUser: () => void,
22-
setMeta: (meta: IMetaReducerState) => void,
28+
29+
interface IHomeProps extends IStateToProps, IDispatchToProps {
2330
}
2431

25-
class Home extends React.Component<IHomeProps, void> {
32+
class Home extends React.Component<IStateToProps & IDispatchToProps, void> {
2633

2734
componentWillMount(): void {
2835
this.props.setMeta({
@@ -58,5 +65,5 @@ class Home extends React.Component<IHomeProps, void> {
5865

5966
}
6067

61-
export default connect(mapStateToProps, mapDispatchToProps)(Home);
68+
export default connect<IStateToProps, IDispatchToProps, any>(mapStateToProps, mapDispatchToProps)(Home);
6269

src/views/landmarks/Header.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import {NavLink} from 'react-router-dom';
33

4-
class Header extends React.Component<void, void> {
4+
class Header extends React.Component {
55

66
public render(): JSX.Element {
77
return (

tsconfig.json

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,46 @@
11
{
22
"compilerOptions": {
3-
"allowJs": true,
43
"allowSyntheticDefaultImports": true,
5-
"alwaysStrict": true,
4+
// no errors on commonjs default import
5+
"allowJs": true,
6+
// include js files
7+
"checkJs": true,
8+
// typecheck js files
69
"declaration": false,
10+
// don't emit declarations
11+
"emitDecoratorMetadata": true,
12+
"experimentalDecorators": true,
13+
"forceConsistentCasingInFileNames": true,
714
"importHelpers": true,
15+
// importing helper functions from tslib
16+
"noEmitHelpers": true,
17+
// disable emitting inline helper functions
818
"jsx": "react",
19+
// process JSX
20+
"lib": [
21+
"dom",
22+
"es2016",
23+
"es2017.object"
24+
],
25+
"target": "es5",
26+
// "es2015" for ES6+ engines
927
"module": "commonjs",
28+
// "es2015" for tree-shaking
1029
"moduleResolution": "node",
30+
"noEmitOnError": true,
31+
"noFallthroughCasesInSwitch": true,
1132
"noImplicitAny": true,
12-
"noUnusedParameters": false,
13-
"removeComments": true,
14-
"pretty": true,
15-
"sourceMap": true,
33+
"noImplicitReturns": true,
1634
"noImplicitThis": true,
17-
"target": "es2015"
35+
"noUnusedLocals": false,
36+
"strictNullChecks": false,
37+
"pretty": true,
38+
"removeComments": true,
39+
"sourceMap": false
1840
},
41+
"include": [
42+
"src/**/*"
43+
],
1944
"exclude": [
2045
"node_modules"
2146
]

yarn.lock

+4
Original file line numberDiff line numberDiff line change
@@ -5688,6 +5688,10 @@ tryit@^1.0.1:
56885688
version "1.0.3"
56895689
resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb"
56905690

5691+
tslib@1.7.1:
5692+
version "1.7.1"
5693+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec"
5694+
56915695
tty-browserify@0.0.0:
56925696
version "0.0.0"
56935697
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"

0 commit comments

Comments
 (0)