Is there a simple and efficient method to achieve the following:
const x: (string|undefined)[] = ['aaa', undefined, 'ccc'];
const y = _.filter(x, it => !!it);
in order for TypeScript to correctly identify y
as string[]
, without needing to create a custom function for filtering? (Essentially, is there a way for the language to automatically narrow the type of a variable within, for example, an if
statement when working with arrays?)