Skip to content

Instantly share code, notes, and snippets.

Last active November 26, 2018 10:39
What would you like to do?
FIX: TS2454: Variable 'newState' is used before being assigned.
export function apiKey(state: ApiKeyState, action: BaseAction) : ApiKeyState {
//Assigning variable here.
let newState: ApiKeyState = state;
switch (action.type) {
case 'ADD_API_KEY':
newState = Object.assign({}, state); = [,
] as string[];
//More actions handling here
//Using only newState in return.
return newState ? newState : API_KEY_INITIAL_STATE;
Copy link

jawys commented Nov 26, 2018

You could even shorten line 18 to the following:

return newState || API_KEY_INITIAL_STATE;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment