Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 7e4eac4

Browse files
committed
add type definitions so that it will compile with noImplicitAny: true
1 parent ceb7a12 commit 7e4eac4

File tree

7 files changed

+21
-21
lines changed

7 files changed

+21
-21
lines changed

react-with-type-safe-flux/src/components/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import GreetingState from '../types/GreetingState';
55
import WhoToGreet from './WhoToGreet';
66
import Greeting from './Greeting';
77

8-
class App extends React.Component<any, GreetingState> {
9-
constructor(props) {
8+
class App extends React.Component<{}, GreetingState> {
9+
constructor(props: {}) {
1010
super(props);
1111
this.state = this._getStateFromStores();
1212
}

react-with-type-safe-flux/src/components/Greeting.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface Props {
77
}
88

99
class Greeting extends React.Component<Props, any> {
10-
constructor(props) {
10+
constructor(props: Props) {
1111
super(props);
1212
}
1313

@@ -28,7 +28,7 @@ class Greeting extends React.Component<Props, any> {
2828
);
2929
}
3030

31-
_onClick = (event) => {
31+
_onClick = (event: React.MouseEvent) => {
3232
GreetingActions.removeGreeting(this.props.targetOfGreeting);
3333
}
3434
}

react-with-type-safe-flux/src/components/WhoToGreet.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface Props {
66
}
77

88
class WhoToGreet extends React.Component<Props, any> {
9-
constructor(props) {
9+
constructor(props: Props) {
1010
super(props);
1111
}
1212

@@ -35,12 +35,12 @@ class WhoToGreet extends React.Component<Props, any> {
3535
return !this.props.newGreeting;
3636
}
3737

38-
_handleNewGreetingChange = (event) => {
39-
const { target: { value: newGreeting } } = event;
38+
_handleNewGreetingChange = (event: React.FormEvent) => {
39+
const newGreeting = (event.target as HTMLInputElement).value;
4040
GreetingActions.newGreetingChanged(newGreeting);
4141
}
4242

43-
_onSubmit = (event) => {
43+
_onSubmit = (event: React.FormEvent) => {
4444
event.preventDefault();
4545

4646
if (!this._preventSubmission) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Dispatcher } from 'flux';
22

3-
const dispatcherInstance = new Dispatcher();
3+
const dispatcherInstance: Flux.Dispatcher<any> = new Dispatcher();
44

55
export default dispatcherInstance;

react-with-type-safe-flux/src/stores/FluxStore.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { EventEmitter } from 'events';
22

33
const CHANGE_EVENT = 'change';
44

5-
class FluxStore<TState> {
5+
class FluxStore<PayloadType, TState> {
66
_changed: boolean;
77
_emitter: EventEmitter;
88
dispatchToken: string;
9-
_dispatcher: Flux.Dispatcher<any>;
9+
_dispatcher: Flux.Dispatcher<PayloadType>;
1010
_cleanStateFn: () => TState;
1111
_state: TState;
1212

13-
constructor(dispatcher, cleanStateFn) {
13+
constructor(dispatcher: Flux.Dispatcher<PayloadType>, cleanStateFn: () => TState) {
1414
this._emitter = new EventEmitter();
1515
this._changed = false;
1616
this._dispatcher = dispatcher;
17-
this.dispatchToken = dispatcher.register(payload => {
17+
this.dispatchToken = dispatcher.register((payload: PayloadType) => {
1818
this._invokeOnDispatch(payload);
1919
});
2020

@@ -31,11 +31,11 @@ class FluxStore<TState> {
3131

3232
hasChanged() { return this._changed; }
3333

34-
addChangeListener(callback) {
34+
addChangeListener(callback: () => void) {
3535
this._emitter.on(CHANGE_EVENT, callback);
3636
}
3737

38-
removeChangeListener(callback) {
38+
removeChangeListener(callback: () => void) {
3939
this._emitter.removeListener(CHANGE_EVENT, callback);
4040
}
4141

@@ -44,15 +44,15 @@ class FluxStore<TState> {
4444
this._state = this._cleanStateFn();
4545
}
4646

47-
_invokeOnDispatch(payload) {
47+
_invokeOnDispatch(payload: PayloadType) {
4848
this._changed = false;
4949
this._onDispatch(payload);
5050
if (this._changed) {
5151
this._emitter.emit(CHANGE_EVENT);
5252
}
5353
}
5454

55-
_onDispatch(payload) {
55+
_onDispatch(payload: PayloadType) {
5656
if (process.env.NODE_ENV !== 'production') {
5757
console.error(`${this.constructor.name} has not overridden FluxStore.__onDispatch(), which is required`); // eslint-disable-line no-console
5858
}

react-with-type-safe-flux/src/stores/GreetingStore.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import GreetingActionTypes from '../constants/action-types/GreetingActionTypes';
33
import AppDispatcher from '../dispatcher/AppDispatcher';
44
import GreetingState from '../types/GreetingState';
55

6-
class GreeterStore extends FluxStore<GreetingState> {
7-
constructor(dispatcher) {
6+
class GreeterStore<TPayload> extends FluxStore<TPayload, GreetingState> {
7+
constructor(dispatcher: Flux.Dispatcher<TPayload>) {
88
super(dispatcher, () => ({
99
greetings: [],
1010
newGreeting: ''
@@ -15,7 +15,7 @@ class GreeterStore extends FluxStore<GreetingState> {
1515
return this._state
1616
}
1717

18-
_onDispatch(action) {
18+
_onDispatch(action: any) {
1919
switch(action.type) {
2020
case GreetingActionTypes.ADD_GREETING:
2121
this._state.newGreeting = '';

react-with-type-safe-flux/src/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"compilerOptions": {
1010
"jsx": "preserve",
1111
"target": "es6",
12-
"noImplicitAny": false,
12+
"noImplicitAny": true,
1313
"removeComments": false,
1414
"preserveConstEnums": true,
1515
"sourceMap": true

0 commit comments

Comments
 (0)