const list: string[] = getNames();
const first = list[0];
string | undefinedThe answer is string | undefined. The option adds undefined to every read from an array or index signature, because the index might be out of range.string is the tempting wrong answer. You get plain string only without the option, even when the array is empty.
Read more
- TSConfig reference (https://www.typescriptlang.org/tsconfig)typescriptlang.org