There's a minor obstacle blocking my way:
const foo = ["foo", "bar"]; // type "string[]"
const foundFoo = foo.find(fooEl => fooEl === "notFooBar"); // type "string" -> why not "string | undefined"
After reviewing the type definitions of array.find
, I noticed that it does mention the possibility of returning undefined. However, my environment is indicating that foundFoo
is of type string
instead of string | undefined
. Why is this discrepancy occurring?
Upon searching StackOverflow for similar queries, most questions were about why it "could" be undefined, so I'm unsure why my environment is displaying the opposite result.