title: How can I use createContext with TypeScript?
body: <p>I found a blog where they did it as follows:</p>
  <pre><code>import { createContext } from 'react';
  
  type ContextProps = {
      alert: any,
      showAlert: any
  };
  
  const alertContext = createContext&lt;Partial&lt;ContextProps&gt;&gt;({});
  
  export default alertContext;
  </code></pre>
  <p>I created another file in which I set up the functions, like this:</p>
  <pre><code>const AlertState: SFC&lt;AlertStateProps&gt; = (props) =&gt; {
  
          const initialState = {
              alert: null
          }
      
          const [state, dispatch] = useReducer(alertReducer, initialState);
      
          // Functions
          const showAlert = (msg: any) =&gt; {
              dispatch({
                  type: SHOW_ALERT,
                  payload: {
                      msg
                  }
              });
      
              // After 5 seconds clean error message
              setTimeout(() =&gt; {
                  dispatch({
                      type: HIDE_ALERT
                  })
              }, 5000);
          }
  
      return (  
          &lt;alertContext.Provider
              value={{
                  alert: state.alert,
                  showAlert
              }}
          &gt;
              {props.children}
          &lt;/alertContext.Provider&gt;
      );
  }
   
  export default AlertState;
  </code></pre>
  <p>But, when I call <code>alertContext</code> in another file, like this:</p>
  <pre><code>const Login = (props) =&gt; {
  
  const alertContext = useContext(AlertContext);
  const { alert, showAlert } = alertContext;
  
  console.log('context', alertContext);
  ...
  }
  </code></pre>
  <p>In the <code>console.log</code> I can see that it takes the empty object and not the properties that are declared in the interface.</p>
  <p><a href="https://i.stack.imgur.com/fI2Oo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fI2Oo.png" alt="enter image description here" /></a></p>
  <p>Someone knows what can I do?</p>