Автовывод предикатов типа

Изменения в новых версиях / TypeScript 5.5

// *** before: ***
function isString(x: unknown) {
    return typeof x === "string";
}
const arr: (string | number)[] = ["a", 1, "b"];
const strings = arr.filter(isString);
//strings: (string | number)[] - without an explicit "x is string" the filter
//narrows nothing

// *** in version 5.5: ***
function isStringInferred(x: unknown) {
    return typeof x === "string"; // the predicate "x is string" is inferred
}
const stringsNarrowed = arr.filter(isStringInferred);
// stringsNarrowed: string[]