title: Second argument in sort function gives typescript error - Object is possibly 'undefined'
body: <p>Second argument e.g <strong>b</strong> in sort function gives typescript error - Object is possibly 'undefined'. which I find it very weird as <strong>a</strong> is not, however they are the same type.</p>
  <pre><code>stories.value.sort((a, b) =&gt; a.story_score? - b.story_score?)
  </code></pre>
  <p>The whole context is here:</p>
  <pre><code>import { ref, Ref } from &quot;vue&quot;
  import useApi from &quot;./useApi&quot;;
  
  export interface Story {
    by: string
    descendants?: number
    id: number
    kids?: number[]
    score?: number
    time: number
    title?: string
    type: string
    url?: string
  }
  
  export interface Author {
    created: number
    id: string,
    karma: number,
    submitted: number[]
  }
  
  export interface StoryWithAuthor {
    author_id: string
    author_karma_score: number
    story_title?: string
    story_url ?: string
    timestamp: number
    story_score ?: number
  }
  
  const error: Ref&lt;string&gt;= ref('')
  const stories: Ref&lt;StoryWithAuthor[]&gt; = ref([])
  
  const getStories = async () :Promise&lt;void&gt; =&gt; {
    error.value = ''
    stories.value = []
   
    try {
      const { response: stories, request } = useApi&lt;number[]&gt;(
        'topstories.json'
      );
      await request()
  
      if (stories.value) {
        const storyIds: number[] = stories.value.sort(() =&gt; Math.random() - Math.random()).slice(0, 10)
        await getStoryWithAuthor(storyIds)
      }
    } catch (err: unknown) {
      error.value = 'Error fetching stories'
    }
  }
  
  const getStoryWithAuthor = async(storyIds: number[]): Promise&lt;void&gt; =&gt; {
    error.value = ''
    stories.value = []
    try {
      for (const id of storyIds) {
        const { response: story, request } = useApi&lt;Story&gt;(
          `item/${id}.json`
        );
        await request()
        if (story.value) {
          const author = await getAuthor(story.value.by)
          if (author) {
            stories.value.push(
              {
                author_id: author.id,
                author_karma_score: author.karma,
                story_title: story.value.title,
                story_url: story.value.url,
                timestamp: story.value.time,
                story_score: story.value.score,
              }
            )
          }
          // Typescript complains about second argument
          stories.value.sort((a, b) =&gt; a.story_score? - b.story_score?)
        }
    
      }
    } catch (err: unknown) {
      error.value = 'Error fetching story'
    }
  }
  
  const getAuthor = async (userId: string):Promise&lt;Author | undefined&gt; =&gt; {
    error.value = ''
    try {
  
      const { response: author, request } = useApi&lt;Author&gt;(
          `user/${userId}.json`
        );
      await request()
      return author.value
    } catch (err: unknown) {
      error.value = 'Error fetching author'
    }
  }
  
  type useStories = { getStories: () =&gt; Promise&lt;void&gt;, getStoryWithAuthor: (storyIds: number[]) =&gt; Promise&lt;void&gt;, stories: Ref&lt;StoryWithAuthor[]&gt;, error: Ref&lt;unknown&gt; }
  
  const useStories = () :useStories =&gt; ({
    getStories, getStoryWithAuthor, stories, error,
  })
  
  
  export default useStories
  </code></pre>