Модификатор const у параметров типа

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

// *** before: ***
function getNames<T extends string>(arr: T[]) {
    return arr;
}
const namesWidened = getNames(["a", "b"]); // inferred string[], the literals
//are gone
function needsAsConst<T extends readonly string[]>(arr: T) { return arr; }
const namesAsConst = needsAsConst(["a", "b"] as const); // as const had to be
//written by hand

// *** in version 5.0: ***
function getNamesConst<const T extends string[]>(arr: T) {
    return arr;
}
const namesLiteral = getNamesConst(["a", "b"]);
// namesLiteral: readonly ["a", "b"] - with no as const at the call