Improve type checks

This commit is contained in:
riggraz
2019-09-26 16:03:41 +02:00
parent 322c8e51cf
commit 678d2eaacf
16 changed files with 67 additions and 26 deletions

View File

@@ -5,7 +5,7 @@ import { State } from '../reducers/rootReducer';
export const CHANGE_POST_BOARD_SUCCESS = 'CHANGE_POST_BOARD_SUCCESS'; export const CHANGE_POST_BOARD_SUCCESS = 'CHANGE_POST_BOARD_SUCCESS';
export interface ChangePostBoardSuccessAction { export interface ChangePostBoardSuccessAction {
type: typeof CHANGE_POST_BOARD_SUCCESS; type: typeof CHANGE_POST_BOARD_SUCCESS;
newBoardId; newBoardId: number;
} }
const changePostBoardSuccess = (newBoardId: number): ChangePostBoardSuccessAction => ({ const changePostBoardSuccess = (newBoardId: number): ChangePostBoardSuccessAction => ({

View File

@@ -5,7 +5,7 @@ import { State } from '../reducers/rootReducer';
export const CHANGE_POST_STATUS_SUCCESS = 'CHANGE_POST_STATUS_SUCCESS'; export const CHANGE_POST_STATUS_SUCCESS = 'CHANGE_POST_STATUS_SUCCESS';
export interface ChangePostStatusSuccessAction { export interface ChangePostStatusSuccessAction {
type: typeof CHANGE_POST_STATUS_SUCCESS; type: typeof CHANGE_POST_STATUS_SUCCESS;
newPostStatusId; newPostStatusId: number;
} }
const changePostStatusSuccess = (newPostStatusId: number): ChangePostStatusSuccessAction => ({ const changePostStatusSuccess = (newPostStatusId: number): ChangePostStatusSuccessAction => ({

View File

@@ -11,12 +11,12 @@ interface SetCommentReplyBodyAction {
body: string; body: string;
} }
export const toggleCommentReply = (commentId): ToggleCommentReplyAction => ({ export const toggleCommentReply = (commentId: number): ToggleCommentReplyAction => ({
type: TOGGLE_COMMENT_REPLY, type: TOGGLE_COMMENT_REPLY,
commentId, commentId,
}); });
export const setCommentReplyBody = (commentId, body): SetCommentReplyBodyAction => ({ export const setCommentReplyBody = (commentId: number, body: string): SetCommentReplyBodyAction => ({
type: SET_COMMENT_REPLY_BODY, type: SET_COMMENT_REPLY_BODY,
commentId, commentId,
body, body,

View File

@@ -1,7 +1,7 @@
import ICommentJSON from '../interfaces/json/IComment'; import ICommentJSON from '../interfaces/json/IComment';
export const COMMENT_REQUEST_SUCCESS = 'COMMENT_REQUEST_SUCCESS'; export const COMMENT_REQUEST_SUCCESS = 'COMMENT_REQUEST_SUCCESS';
interface CommentRequestSuccessAction { export interface CommentRequestSuccessAction {
type: typeof COMMENT_REQUEST_SUCCESS; type: typeof COMMENT_REQUEST_SUCCESS;
comment: ICommentJSON; comment: ICommentJSON;
} }

View File

@@ -28,7 +28,7 @@ export type CommentSubmitActionTypes =
CommentSubmitSuccessAction | CommentSubmitSuccessAction |
CommentSubmitFailureAction; CommentSubmitFailureAction;
const commentSubmitStart = (parentId): CommentSubmitStartAction => ({ const commentSubmitStart = (parentId: number): CommentSubmitStartAction => ({
type: COMMENT_SUBMIT_START, type: COMMENT_SUBMIT_START,
parentId, parentId,
}); });
@@ -40,17 +40,17 @@ const commentSubmitSuccess = (
comment: commentJSON, comment: commentJSON,
}); });
const commentSubmitFailure = (parentId, error): CommentSubmitFailureAction => ({ const commentSubmitFailure = (parentId: number, error: string): CommentSubmitFailureAction => ({
type: COMMENT_SUBMIT_FAILURE, type: COMMENT_SUBMIT_FAILURE,
parentId, parentId,
error, error,
}); });
export const submitComment = ( export const submitComment = (
postId, postId: number,
body, body: string,
parentId, parentId: number,
authenticityToken, authenticityToken: string,
): ThunkAction<void, State, null, Action<string>> => async (dispatch) => { ): ThunkAction<void, State, null, Action<string>> => async (dispatch) => {
dispatch(commentSubmitStart(parentId)); dispatch(commentSubmitStart(parentId));

View File

@@ -6,6 +6,9 @@ import createStoreHelper from '../../helpers/createStore';
import IBoard from '../../interfaces/IBoard'; import IBoard from '../../interfaces/IBoard';
import { Store } from 'redux';
import { State } from '../../reducers/rootReducer';
interface Props { interface Props {
board: IBoard; board: IBoard;
isLoggedIn: boolean; isLoggedIn: boolean;
@@ -13,7 +16,7 @@ interface Props {
} }
class BoardRoot extends React.Component<Props> { class BoardRoot extends React.Component<Props> {
store: any; store: Store<State, any>;
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);

View File

@@ -8,6 +8,9 @@ import Post from '../../containers/Post';
import IBoard from '../../interfaces/IBoard'; import IBoard from '../../interfaces/IBoard';
import IPostStatus from '../../interfaces/IPostStatus'; import IPostStatus from '../../interfaces/IPostStatus';
import { Store } from 'redux';
import { State } from '../../reducers/rootReducer';
interface Props { interface Props {
postId: number; postId: number;
boards: Array<IBoard>; boards: Array<IBoard>;
@@ -18,7 +21,7 @@ interface Props {
} }
class PostRoot extends React.Component<Props> { class PostRoot extends React.Component<Props> {
store: any; store: Store<State, any>;
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);

View File

@@ -16,7 +16,7 @@ const mapStateToProps = (state: State) => ({
postStatuses: state.postStatuses, postStatuses: state.postStatuses,
}); });
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch: any) => ({
requestPosts(boardId: number, page: number = 1, searchQuery: string = '', postStatusId: number = null) { requestPosts(boardId: number, page: number = 1, searchQuery: string = '', postStatusId: number = null) {
dispatch(requestPosts(boardId, page, searchQuery, postStatusId)); dispatch(requestPosts(boardId, page, searchQuery, postStatusId));
}, },

View File

@@ -1,4 +1,5 @@
import { import {
CommentRequestSuccessAction,
COMMENT_REQUEST_SUCCESS, COMMENT_REQUEST_SUCCESS,
} from '../actions/requestComment'; } from '../actions/requestComment';
@@ -14,7 +15,7 @@ const initialState: IComment = {
const commentReducer = ( const commentReducer = (
state = initialState, state = initialState,
action, action: CommentRequestSuccessAction,
): IComment => { ): IComment => {
switch (action.type) { switch (action.type) {
case COMMENT_REQUEST_SUCCESS: case COMMENT_REQUEST_SUCCESS:

View File

@@ -1,13 +1,16 @@
import { import {
CommentRequestSuccessAction,
COMMENT_REQUEST_SUCCESS, COMMENT_REQUEST_SUCCESS,
} from '../actions/requestComment'; } from '../actions/requestComment';
import { import {
HandleCommentRepliesType,
TOGGLE_COMMENT_REPLY, TOGGLE_COMMENT_REPLY,
SET_COMMENT_REPLY_BODY, SET_COMMENT_REPLY_BODY,
} from '../actions/handleCommentReplies'; } from '../actions/handleCommentReplies';
import { import {
CommentSubmitActionTypes,
COMMENT_SUBMIT_START, COMMENT_SUBMIT_START,
COMMENT_SUBMIT_SUCCESS, COMMENT_SUBMIT_SUCCESS,
COMMENT_SUBMIT_FAILURE, COMMENT_SUBMIT_FAILURE,
@@ -31,7 +34,10 @@ const initialState: CommentRepliesState = {
const commentRepliesReducer = ( const commentRepliesReducer = (
state = initialState, state = initialState,
action, action:
CommentRequestSuccessAction |
HandleCommentRepliesType |
CommentSubmitActionTypes,
) => { ) => {
switch (action.type) { switch (action.type) {
case COMMENT_REQUEST_SUCCESS: case COMMENT_REQUEST_SUCCESS:

View File

@@ -1,4 +1,5 @@
import { import {
CommentsRequestActionTypes,
COMMENTS_REQUEST_START, COMMENTS_REQUEST_START,
COMMENTS_REQUEST_SUCCESS, COMMENTS_REQUEST_SUCCESS,
COMMENTS_REQUEST_FAILURE, COMMENTS_REQUEST_FAILURE,
@@ -7,11 +8,13 @@ import {
import { commentRequestSuccess } from '../actions/requestComment'; import { commentRequestSuccess } from '../actions/requestComment';
import { import {
HandleCommentRepliesType,
TOGGLE_COMMENT_REPLY, TOGGLE_COMMENT_REPLY,
SET_COMMENT_REPLY_BODY, SET_COMMENT_REPLY_BODY,
} from '../actions/handleCommentReplies'; } from '../actions/handleCommentReplies';
import { import {
CommentSubmitActionTypes,
COMMENT_SUBMIT_START, COMMENT_SUBMIT_START,
COMMENT_SUBMIT_SUCCESS, COMMENT_SUBMIT_SUCCESS,
COMMENT_SUBMIT_FAILURE, COMMENT_SUBMIT_FAILURE,
@@ -40,7 +43,10 @@ const initialState: CommentsState = {
const commentsReducer = ( const commentsReducer = (
state = initialState, state = initialState,
action, action:
CommentsRequestActionTypes |
HandleCommentRepliesType |
CommentSubmitActionTypes
): CommentsState => { ): CommentsState => {
switch (action.type) { switch (action.type) {
case COMMENTS_REQUEST_START: case COMMENTS_REQUEST_START:
@@ -55,7 +61,7 @@ const commentsReducer = (
items: action.comments.map( items: action.comments.map(
(comment: ICommentJSON) => commentReducer(undefined, commentRequestSuccess(comment)) (comment: ICommentJSON) => commentReducer(undefined, commentRequestSuccess(comment))
), ),
replies: [commentRepliesReducer(undefined, {type: 'COMMENT_REQUEST_SUCCESS', comment: { id: -1 } }), replies: [commentRepliesReducer(undefined, {type: 'COMMENT_REQUEST_SUCCESS', comment: { id: -1 } as ICommentJSON }),
...action.comments.map( ...action.comments.map(
(comment: ICommentJSON) => commentRepliesReducer(undefined, commentRequestSuccess(comment)) (comment: ICommentJSON) => commentRepliesReducer(undefined, commentRequestSuccess(comment))
)], )],

View File

@@ -50,10 +50,10 @@ interface CurrentPostState {
} }
const initialState: CurrentPostState = { const initialState: CurrentPostState = {
item: postReducer(undefined, {}), item: postReducer(undefined, {} as PostRequestActionTypes),
isLoading: false, isLoading: false,
error: '', error: '',
comments: commentsReducer(undefined, {}), comments: commentsReducer(undefined, {} as CommentsRequestActionTypes),
}; };
const currentPostReducer = ( const currentPostReducer = (

View File

@@ -1,12 +1,15 @@
import { import {
PostRequestActionTypes,
POST_REQUEST_SUCCESS, POST_REQUEST_SUCCESS,
} from '../actions/requestPost'; } from '../actions/requestPost';
import { import {
ChangePostBoardSuccessAction,
CHANGE_POST_BOARD_SUCCESS, CHANGE_POST_BOARD_SUCCESS,
} from '../actions/changePostBoard'; } from '../actions/changePostBoard';
import { import {
ChangePostStatusSuccessAction,
CHANGE_POST_STATUS_SUCCESS, CHANGE_POST_STATUS_SUCCESS,
} from '../actions/changePostStatus'; } from '../actions/changePostStatus';
@@ -25,7 +28,10 @@ const initialState: IPost = {
const postReducer = ( const postReducer = (
state = initialState, state = initialState,
action, action:
PostRequestActionTypes |
ChangePostBoardSuccessAction |
ChangePostStatusSuccessAction,
): IPost => { ): IPost => {
switch (action.type) { switch (action.type) {
case POST_REQUEST_SUCCESS: case POST_REQUEST_SUCCESS:

View File

@@ -37,10 +37,7 @@ const initialState: PostsState = {
haveMore: true, haveMore: true,
areLoading: false, areLoading: false,
error: '', error: '',
filters: { // improve filters: filtersReducer(undefined, {} as ChangeFiltersActionTypes),
searchQuery: '',
postStatusId: null,
},
}; };
const postsReducer = ( const postsReducer = (

View File

@@ -27,6 +27,7 @@
}, },
"version": "0.1.0", "version": "0.1.0",
"devDependencies": { "devDependencies": {
"@types/react-redux": "^7.1.3",
"redux-devtools-extension": "^2.13.8", "redux-devtools-extension": "^2.13.8",
"webpack-dev-server": "^3.8.0" "webpack-dev-server": "^3.8.0"
} }

View File

@@ -820,6 +820,14 @@
"@types/minimatch" "*" "@types/minimatch" "*"
"@types/node" "*" "@types/node" "*"
"@types/hoist-non-react-statics@^3.3.0":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"
integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==
dependencies:
"@types/react" "*"
hoist-non-react-statics "^3.3.0"
"@types/minimatch@*": "@types/minimatch@*":
version "3.0.3" version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
@@ -847,6 +855,16 @@
dependencies: dependencies:
"@types/react" "*" "@types/react" "*"
"@types/react-redux@^7.1.3":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.3.tgz#7efc1e36267e9bf8b24ec89ac30a27a65c94cd25"
integrity sha512-coaQFfn6XrHF/4CSF8eBM9rUbi5TX6qVhS+KF89Z2nC9YdTKTckOpJLJyQocYLrXF0IFX+/ZUJwMvbZ0nNmkDg==
dependencies:
"@types/hoist-non-react-statics" "^3.3.0"
"@types/react" "*"
hoist-non-react-statics "^3.3.0"
redux "^4.0.0"
"@types/react@*", "@types/react@^16.9.2": "@types/react@*", "@types/react@^16.9.2":
version "16.9.2" version "16.9.2"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.2.tgz#6d1765431a1ad1877979013906731aae373de268" resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.2.tgz#6d1765431a1ad1877979013906731aae373de268"
@@ -5932,7 +5950,7 @@ redux-thunk@^2.3.0:
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622" resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"
integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw== integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw==
redux@^4.0.4: redux@^4.0.0, redux@^4.0.4:
version "4.0.4" version "4.0.4"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.4.tgz#4ee1aeb164b63d6a1bcc57ae4aa0b6e6fa7a3796" resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.4.tgz#4ee1aeb164b63d6a1bcc57ae4aa0b6e6fa7a3796"
integrity sha512-vKv4WdiJxOWKxK0yRoaK3Y4pxxB0ilzVx6dszU2W8wLxlb2yikRph4iV/ymtdJ6ZxpBLFbyrxklnT5yBbQSl3Q== integrity sha512-vKv4WdiJxOWKxK0yRoaK3Y4pxxB0ilzVx6dszU2W8wLxlb2yikRph4iV/ymtdJ6ZxpBLFbyrxklnT5yBbQSl3Q==