title: type 'undefined' is not assignable to type, losing type in map()
body: <p>I have an action in my redux toolkit that's attempting to set some state. Relevant code below:</p>
  <p><strong>interfaces</strong></p>
  <pre><code>export interface ProposalTag {
    id: number;
    name: string;
    hex: string;
    color: string;
  }
  
  export interface ProposalSelectedTag {
    proposal_id: number;
    proposal_tag_id: number;
  }
  </code></pre>
  <p><strong>redux</strong></p>
  <pre><code>import { ProposalTag, ProposalSelectedTag } from '../../types/proposalTags';
  
  interface ProposalTagsSlice {
    proposalTags: ProposalTag[];
    selectedProposalTags: ProposalTag[];
  }
  
  const initialState: ProposalTagsSlice = {
    proposalTags: [],
    selectedProposalTags: [],
  };
  
  const matchTags = (
    selectedTags: ProposalSelectedTag[],
    proposalTags: ProposalTag[],
  ): ProposalTag[] =&gt; {
    const tags = selectedTags.map((selectedTag: ProposalSelectedTag) =&gt; {
      return proposalTags.find(proposalTag =&gt; proposalTag.id === selectedTag.proposal_tag_id);
    });
  
    return tags ?? [];
  };
  
  export const proposalTagsSlice = createSlice({
    name: 'proposalTags',
    initialState,
    reducers: {
      setSelectedProposalTags: (state, action: PayloadAction&lt;ProposalSelectedTag[]&gt;) =&gt; {
        if (state.proposalTags === undefined) return;
        state.selectedProposalTags =
          action.payload === null ? [] : matchTags(action.payload, state.proposalTags);
      },
    },
  });
  </code></pre>
  <p>The goal of <code>matchTags</code> is to convert the payload of <code>ProposalSelectedTag[]</code> to <code>ProposalTag[]</code>.  So in theory, <code>ProposalSelectedTag.proposal_tag_id</code></p>
  <p>The type errors I get back are the following:<a href="https://i.stack.imgur.com/3bmIH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3bmIH.png" alt="enter image description here" /></a></p>
  <p>Did I lose typing somewhere in <code>matchTags</code>?</p>