title: Typescript array find possibly undefind
body: <p>I have a collection of data that looks like this:</p>
  
  <pre><code>interface Item {
    name: "one" | "two";
    data: string;
  }
  
  const namedItems: Item[] = [
    {
      name: "one",
      data: "some data one",
    },
    {
      name: "two",
      data: "some data two",
    },
  ];
  </code></pre>
  
  <p>Each item has a name and the value can either be "one" or "two".</p>
  
  <p>Then running an array find on this:</p>
  
  <pre><code>const getData = (query: "one" | "two") =&gt;
    namedItems.find((item): boolean =&gt; query === item.name).data;
  </code></pre>
  
  <p>Throws a typescript error "Object is possibly 'undefined'". Which seems to be because of the fact that finds can possibly not find something but in my example you're only allowed to look for "one" or "two" which would always return a result.</p>
  
  <p>How do I get typescript to know it will always return a result in the find?</p>