How to do an array check (like Array.isArray()) with a readonly array (ReadonlyArray)?
As an example:
type ReadonlyArrayTest = ReadonlyArray<string> | string | undefined;
let readonlyArrayTest: ReadonlyArrayTest;
if (readonlyArrayTest && !Array.isArray(readonlyArrayTest)) {
// Here I expect `readonlyArrayTest` to be a string
// but the TypeScript compiler thinks it's following:
// let readonlyArrayTest: string | readonly string[]
}
With an usual array the TypeScript compiler correctly recognises that it must be a string inside the if condition.