title: useReducer cannot use object.attr as switch case in typescript?
body: <p>I'm trying to combine switch case <code>String</code> into an object, but somehow typescript is mis-interpreting the switch case in <code>useReducer</code>:</p>
  <h2>Before version, this works fine:</h2>
  <pre><code>export const LOGIN_USER = &quot;LOGIN_USER&quot;;
  export const LOGOUT_USER = &quot;LOGOUT_USER&quot;;
  
  export type AuthActionType = LogInUser | LogOutUser;
  
  type LogInUser = { type: typeof LOGIN_USER; payload: User }; // &lt;- notice this
  type LogOutUser = { type: typeof LOGOUT_USER };
  
  export default function authReducer(
    state: AuthStateType,
    action: AuthActionType
  ) {
    switch (action.type) {
      case LOGIN_USER: {
        return {
          ...state,
          user: {
            username: action.payload.username, // &lt;- correctly inferring action.payload.username 
            password: action.payload.password
          }
        };
      }
  
      case LOGOUT_USER: {
        return {
          ...state,
          user: null
        };
      }
  
      default: {
        return state;
      }
    }
  }
  </code></pre>
  <h2>However this breaks, after putting the <code>switch case</code> into an object:</h2>
  <pre><code>export const AUTH = {
    LOGIN_USER: &quot;LOGIN_USER&quot;,
    LOGOUT_USER: &quot;LOGOUT_USER&quot;
  };
  
  export type AuthActionType = LogInUser | LogOutUser;
  
  type LogInUser = { type: typeof AUTH.LOGIN_USER; payload: User };  // &lt;- notice this
  type LogOutUser = { type: typeof AUTH.LOGOUT_USER };
  
  export default function authReducer(
    state: AuthStateType,
    action: AuthActionType
  ) {
    switch (action.type) {
      case LOGIN_USER: {
        return {
          ...state,
          user: {
            username: action.payload.username,  // &lt;- error over here, cannot infer the correct case?
            password: action.payload.password
          }
        };
      }
  
      case LOGOUT_USER: {
        return {
          ...state,
          user: null
        };
      }
  
      default: {
        return state;
      }
    }
  }
  </code></pre>
  <p>Only by changing the type definition from <code>type: typeof LOGIN_USER</code> to <code>type: typeof AUTH.LOGIN_USER</code>, typescript breaks the switch case, how's this happenning?</p>
  <p><a href="https://codesandbox.io/s/priceless-hill-jmc1uh?file=/src/App.tsx" rel="nofollow noreferrer">Sandbox</a>, please take a look at this minimum reproduced version.</p>