I realise this question is not specific to typescript, but leaving the below line (B) uncommented would give an error Property 'length' does not exist on type 'String | Number'. Is there some way to make it possible for typescript to know that all the elements are now only string (after the filtering is done)?
const array_: (String| Number)[] = [99, "Hello, World!"];
array_.map((e) => {if (typeof e === "string") console.log(e.length)}) // A
// array_.filter((e) => typeof e === "string").map((e) => {console.log(e.length)}) // B