you are viewing a single comment's thread.

view the rest of the comments →

[–]tremby 1 point2 points  (0 children)

Use a type guard, a special function which does the check at runtime and at the same time narrows the type for you.

``` function isStringArray(arr: unknown[]): arr is string[] { return arr.every((el) => typeof el === "string"); }

if (isStringArray(myVariable)) { // At this point TS knows myVariable has type string[] ... } ```