Skip to content

Instantly share code, notes, and snippets.

@dooman87
Created January 2, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dooman87/61fc972e89c115b0c16ce1b9a519328c to your computer and use it in GitHub Desktop.
Save dooman87/61fc972e89c115b0c16ce1b9a519328c to your computer and use it in GitHub Desktop.
export function apiKey(state: ApiKeyState, action: BaseAction) : ApiKeyState {
let newState: ApiKeyState;
switch (action.type) {
case 'ADD_API_KEY':
newState = Object.assign({}, state);
newState.data.apiKeys = [
...state.data.apiKeys,
action.payload.Key
] as string[];
break;
//More actions handling here
//...
}
//ERROR: TS2454:Variable 'newState' is used before being assigned.
if (newState) {
return newState;
} else {
return state ? state : API_KEY_INITIAL_STATE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment