Typescript says array.pop() might return undefined even when array is guaranteed to contain elements

See microsoft/TypeScript#30406 for a canonical answer. For the question, “why does the compiler think that pop() might return undefined even when I check the array’s length“, the short answer is “because the TypeScript standard library’s call signature for the pop() method on Array<T> returns T | undefined“: interface Array<T> { // … elided pop(): T … Read more