Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit fbdd7a3

Browse files
Merge pull request #19 from thefringeninja/no-implicity-any
Set noImplicitAny to true
2 parents 077efc1 + 67d0706 commit fbdd7a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+461
-337
lines changed

.babelrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
"@types/react-dom": "^16.0.9",
2323
"@types/react-tap-event-plugin": "^0.0.30",
2424
"@types/react-transition-group": "^2.0.14",
25+
"@types/remarkable": "^1.7.1",
2526
"@types/uuid": "^3.4.4",
2627
"babel-plugin-module-resolver": "3.1.1",
2728
"prettier": "1.14.2",
2829
"react-scripts-ts": "3.1.0",
2930
"source-map-explorer": "1.6.0",
3031
"tslint-config-prettier": "1.15.0",
32+
"tslint-immutable": "4.8.0",
33+
"tslint-react": "3.6.0",
3134
"typescript": "3.1.3",
3235
"typesync": "0.4.0"
3336
},

src/SqlStreamStoreBrowser.tsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AppBar, CssBaseline, Toolbar, Typography } from '@material-ui/core';
22
import { MuiThemeProvider } from '@material-ui/core/styles';
3+
import { JSONSchema7 } from 'json-schema';
34
import React, { ComponentType } from 'react';
45
import { Observable as obs } from 'rxjs';
56
import {
@@ -14,13 +15,13 @@ import { SqlStreamStore } from './components/Icons';
1415
import { connect, createState } from './reactive';
1516
import { actions, store, Viewer } from './stream-store';
1617
import theme from './theme';
17-
import { HalLink, HalLinks } from './types';
18+
import { AuthorizationProps, HalLink, HalLinks } from './types';
1819
import { mediaTypes } from './utils';
1920

20-
const getSelfAlias = links =>
21+
const getSelfAlias = (links: HalLinks) =>
2122
Object.keys(links)
2223
.flatMap(rel => links[rel])
23-
.filter(({ rel }) => rel.indexOf('streamStore:') === 0)
24+
.filter(({ rel }) => rel && rel.indexOf('streamStore:') === 0)
2425
.filter(
2526
({ rel, href }) =>
2627
!!links.self.filter(link => link.href === href).length,
@@ -36,20 +37,21 @@ const self$ = store.hal$.links$
3637
interface SqlStreamStoreBrowserState {
3738
loading: boolean;
3839
mediaType: string;
39-
links: HalLinks;
40+
_links: HalLinks;
4041
self: HalLink;
42+
forms: { [rel: string]: JSONSchema7 };
4143
}
4244
const state$ = createState<SqlStreamStoreBrowserState>(
4345
obs.merge(
4446
self$.map(self => ['self', () => self]),
45-
store.hal$.links$.map(links => ['links', () => links]),
47+
store.hal$.links$.map(links => ['_links', () => links]),
4648
store.hal$.forms$.map(forms => ['forms', () => forms]),
4749
store.hal$.loading$.map(loading => ['loading', () => loading]),
4850
store.hal$.mediaType$.map(mediaType => ['mediaType', () => mediaType]),
4951
),
5052
obs.of({
53+
_links: {},
5154
forms: {},
52-
links: {},
5355
loading: false,
5456
mediaType: mediaTypes.hal,
5557
self: {
@@ -62,7 +64,7 @@ const onNavigate = (link: HalLink, authorization: string | undefined) =>
6264
link.href.indexOf('#') === -1 &&
6365
actions.get.request.next({ link, headers: { authorization } });
6466

65-
const initialNavigation = ({ authorization }) =>
67+
const initialNavigation = ({ authorization }: AuthorizationProps) =>
6668
onNavigate(
6769
{ href: window.location.href, type: mediaTypes.any },
6870
authorization,
@@ -82,29 +84,31 @@ const Hero = () => (
8284
const SqlStreamStoreBrowser: ComponentType<
8385
SqlStreamStoreBrowserState
8486
> = withAuthorization()(
85-
mount<SqlStreamStoreBrowserState & { authorization: string | undefined }>(
86-
initialNavigation,
87-
)(({ loading, ...props }) => (
88-
<MuiThemeProvider theme={theme}>
89-
<div>
90-
<CssBaseline />
91-
<Hero />
92-
<Loading open={loading} />
93-
<NavigationProvider onNavigate={onNavigate}>
94-
<Viewer {...props} />
95-
<Notifications />
96-
</NavigationProvider>
97-
</div>
98-
</MuiThemeProvider>
99-
)),
87+
mount<SqlStreamStoreBrowserState & AuthorizationProps>(initialNavigation)(
88+
({ loading, ...props }) => (
89+
<MuiThemeProvider theme={theme}>
90+
<div>
91+
<CssBaseline />
92+
<Hero />
93+
<Loading open={loading} />
94+
<NavigationProvider onNavigate={onNavigate}>
95+
<Viewer {...props} />
96+
<Notifications />
97+
</NavigationProvider>
98+
</div>
99+
</MuiThemeProvider>
100+
),
101+
),
100102
);
101103

102104
const AuthorizedSqlStreamStoreBrowser: ComponentType<
103-
SqlStreamStoreBrowserState & { authorization: string | undefined }
105+
SqlStreamStoreBrowserState & AuthorizationProps
104106
> = ({ authorization, ...props }) => (
105107
<AuthorizationProvider authorization={authorization}>
106108
<SqlStreamStoreBrowser {...props} />
107109
</AuthorizationProvider>
108110
);
109111

110-
export default connect(state$)(AuthorizedSqlStreamStoreBrowser);
112+
export default connect<SqlStreamStoreBrowserState, AuthorizationProps>(state$)(
113+
AuthorizedSqlStreamStoreBrowser,
114+
);
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
import React, { ReactNode, StatelessComponent } from 'react';
1+
import React, { ComponentType, ReactNode, StatelessComponent } from 'react';
2+
import { AuthorizationProps } from '../types';
23
import getDisplayName from './getDisplayName';
34

45
const { Consumer, Provider } = React.createContext<string | undefined>(
56
undefined,
67
);
78

8-
const AuthorizationProvider: StatelessComponent<{
9-
authorization: string | undefined;
10-
children: ReactNode;
11-
}> = ({ authorization, children }) => (
9+
const AuthorizationProvider: StatelessComponent<
10+
AuthorizationProps & {
11+
children: ReactNode;
12+
}
13+
> = ({ authorization, children }) => (
1214
<Provider value={authorization}>{children}</Provider>
1315
);
1416

1517
export default AuthorizationProvider;
1618

17-
const withAuthorization = () => WrappedComponent => {
18-
const Component = props => (
19+
const withAuthorization = () => <T extends object>(
20+
WrappedComponent: ComponentType<T & AuthorizationProps>,
21+
) => {
22+
const Component = (props: T) => (
1923
<Consumer>
2024
{authorization => (
2125
<WrappedComponent {...props} authorization={authorization} />
@@ -26,7 +30,7 @@ const withAuthorization = () => WrappedComponent => {
2630
'WithAuthorization',
2731
WrappedComponent,
2832
);
29-
return Component;
33+
return Component as ComponentType<T>;
3034
};
3135

3236
export { withAuthorization };

src/components/HyperMediaControls/Dialog.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ import {
55
DialogContent,
66
DialogTitle,
77
Slide,
8+
Theme,
89
withStyles,
910
WithStyles,
1011
} from '@material-ui/core';
11-
import React, { PureComponent, StatelessComponent } from 'react';
12-
1312
import { SlideProps } from '@material-ui/core/Slide';
13+
import React, { FormEvent, PureComponent, StatelessComponent } from 'react';
1414
import { HalLink } from '../../types';
1515
import RelIcon from '../RelIcon';
1616
import HelpButton from './HelpButton';
1717
import RelButton from './RelButton';
18-
const styles = theme => ({
18+
19+
const styles = (theme: Theme) => ({
1920
button: {
2021
margin: theme.spacing.unit,
2122
},
@@ -53,7 +54,7 @@ export default withStyles(styles)(
5354
open: false,
5455
});
5556

56-
_onSubmit = e => {
57+
_onSubmit = (e: FormEvent) => {
5758
const { onSubmit } = this.props;
5859

5960
e.preventDefault();

src/components/HyperMediaControls/FormButton.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import React, { PureComponent } from 'react';
1+
import { JSONSchema7 } from 'json-schema';
2+
import React, { FormEvent, PureComponent } from 'react';
23
import { SchemaForm } from 'react-schema-form';
3-
import { HalLink, NavigatableProps } from '../../types';
4+
import { AuthorizationProps, FormActions, HalLink } from '../../types';
45
import { withAuthorization } from '../AuthorizationProvider';
56
import Dialog from './Dialog';
67
import TextAreaField from './TextAreaField';
@@ -11,12 +12,12 @@ const mapper = {
1112
uuid: UuidField,
1213
};
1314

14-
const getValue = value => {
15+
const getValue = (value: FormEvent<HTMLInputElement>) => {
1516
if (typeof value === 'object') {
1617
try {
17-
return JSON.parse(value.target.value);
18+
return JSON.parse(value.currentTarget.value);
1819
} catch (e) {
19-
return value.target.value;
20+
return value.currentTarget.value;
2021
}
2122
}
2223

@@ -26,10 +27,9 @@ const getValue = value => {
2627
interface FormButtonProps {
2728
rel: string;
2829
link: HalLink;
29-
actions;
30+
actions: FormActions;
3031
curies: HalLink[];
31-
schema;
32-
title: string;
32+
schema: JSONSchema7;
3333
}
3434

3535
interface FormButtonState {
@@ -39,7 +39,7 @@ interface FormButtonState {
3939
}
4040

4141
class FormButton extends PureComponent<
42-
FormButtonProps & NavigatableProps,
42+
FormButtonProps & AuthorizationProps,
4343
FormButtonState
4444
> {
4545
state = {
@@ -60,7 +60,7 @@ class FormButton extends PureComponent<
6060
}
6161
};
6262

63-
_onModelChange = (key, value) => {
63+
_onModelChange = (key: string, value: FormEvent<HTMLInputElement>) => {
6464
const { model, ...state } = this.state;
6565
this.setState({
6666
...state,

src/components/HyperMediaControls/HelpButton.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ const getCurie = (rel: string, curies: HalLink[]): HalLink => {
1717
const [prefix, rest] = rel.split(':', 2);
1818

1919
return !rest || rest.indexOf(':') !== -1
20-
? { href: rel }
20+
? { href: rel, rel }
2121
: curies
2222
.filter(({ name }) => name === prefix)
2323
.map(({ href, ...link }) => ({
2424
...link,
2525
href: uriTemplate
2626
.parse(decodeURI(href))
2727
.expand({ rel: rest }),
28-
}))[0] || { href: rel };
28+
}))[0] || { href: rel, rel };
2929
};
3030

3131
interface DocumentationProps {
@@ -88,8 +88,7 @@ class HelpButton extends PureComponent<HelpButtonProps, HelpButtonState> {
8888
disabled: false,
8989
...getCurie(rel, curies),
9090
});
91-
state = {
92-
curies: [],
91+
state: HelpButtonState = {
9392
disabled: true,
9493
documentation: '',
9594
href: '',

src/components/HyperMediaControls/LinkButton.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PropTypes, TextField } from '@material-ui/core';
2-
import React, { PureComponent, StatelessComponent } from 'react';
2+
import React, { ComponentType, FormEventHandler, PureComponent } from 'react';
33
import uriTemplate from 'uri-template';
44
import { HalLink, NavigatableProps } from '../../types';
55
import { preventDefault } from '../../utils';
@@ -18,19 +18,23 @@ interface TemplatedLinkButtonProps extends LinkButtonProps {
1818
readonly curies: HalLink[];
1919
}
2020

21-
const TemplatedLinkButton: StatelessComponent<
21+
const TemplatedLinkButton: ComponentType<
2222
TemplatedLinkButtonProps
23-
> = withNavigation()(
23+
> = withNavigation<TemplatedLinkButtonProps>()(
2424
class extends PureComponent<
2525
TemplatedLinkButtonProps & NavigatableProps,
2626
{ [variable: string]: string }
2727
> {
2828
state = {};
2929

30-
_onChange = variable => ({ target }) =>
30+
_onChange = (
31+
variable: string,
32+
): FormEventHandler<
33+
HTMLTextAreaElement | HTMLInputElement | HTMLSelectElement
34+
> => ({ currentTarget }) =>
3135
this.setState({
3236
...this.state,
33-
[variable]: target.value,
37+
[variable]: currentTarget.value,
3438
});
3539

3640
render() {
@@ -70,9 +74,9 @@ interface NonTemplatedLinkButtonProps extends LinkButtonProps {
7074
readonly title: string;
7175
}
7276

73-
const NonTemplatedLinkButton: StatelessComponent<
77+
const NonTemplatedLinkButton: ComponentType<
7478
NonTemplatedLinkButtonProps
75-
> = withNavigation()(
79+
> = withNavigation<NonTemplatedLinkButtonProps>()(
7680
({
7781
link,
7882
rel,

src/components/HyperMediaControls/RelButton.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Button } from '@material-ui/core';
22
import { ButtonProps } from '@material-ui/core/Button';
3-
import { SvgIconProps } from '@material-ui/core/SvgIcon';
4-
import React, { ReactNode, StatelessComponent } from 'react';
3+
import React, { StatelessComponent } from 'react';
54
import RelIcon from '../RelIcon';
65

76
interface RelButtonProps {

src/components/HyperMediaControls/TextAreaField.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { TextField } from '@material-ui/core';
2-
import React, { ComponentType, StatelessComponent } from 'react';
3-
import { ComposedComponent } from 'react-schema-form';
4-
import { FormInputProps } from './reactSchemaForms';
2+
import React, { StatelessComponent } from 'react';
3+
import {
4+
ComposedComponent,
5+
ReactSchemaFormInputProps,
6+
} from 'react-schema-form';
57

6-
const TextAreaField: StatelessComponent<FormInputProps> = ({
8+
const TextAreaField: StatelessComponent<ReactSchemaFormInputProps> = ({
79
form,
810
error,
911
onChangeValidate,
@@ -27,6 +29,4 @@ const TextAreaField: StatelessComponent<FormInputProps> = ({
2729
</div>
2830
);
2931

30-
export default ComposedComponent.default(TextAreaField) as ComponentType<
31-
FormInputProps
32-
>;
32+
export default ComposedComponent.default(TextAreaField);

0 commit comments

Comments
 (0)