π Search Terms
isarray 5.8
π Version & Regression Information
- This changed between versions 5.7 and 5.8
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.9.2#code/KYDwDg9gTgLgBAYwgOwM72MgrgWzgYQEMZgBzaATzgG8BYAKDibh2BkIBNjC4BeOAEQB9Ia3Zd2AgDQNmcGBDAAbYADdgSvoIXK1G6bOYwAlqyXHkwLQI5qFEJagB0JsxeAHGzBGCwAFKAgAM2MVKGtVAA4nHywhMECQsM85DmNUQgAjFQ4AIQoAEWAgwiwlGCFXDXdrNIzs4A4AWkyKJtsSsph2uwgHZyrzSxTmOqyc-KLO8qFYgODQ4HD+G3Txxpa2jtLypqiY33jExahPAF8GBlBIWHkKMCsiEnIoY2BUAB58OFASZA5UARiGRKFoniCoBQAHx8QxMAA+cAAFEj0K9kKQ4IjVBBjBwAJRwABkNDgAG0BHBZhAcDhCABlYBgQhQYEccEvCgCAC6AC4CABuOBnfFwrGCy70K7gaDwIJYZAIEwoOAAK1xyA50Den2+v0wAKBz0oUKRCGBLx1-PwZO5+OtFu17y+MLoXiYUDYWCgyEQjte7yc6osSOkAkJhEBWoDuqhAoYFyl9Gusrg8sVyt9CmjOrN-qtRohOvFns4KCUVGjFFt9sLlveNDFnpg3t9AEEoKyKE50h2u3njTHRe65HAAPxqjU594DovvYej5j882DnXx+iJoA
π» Code
export const enum Category {
metadata = "__metadata",
toplevel = "toplevel",
timeline = "devtools.timeline",
cpuProfiler = "v8.cpu_profiler",
disabledByDefault_timeline = "disabled-by-default-devtools.timeline",
disabledByDefault_cpuProfiler = "disabled-by-default-v8.cpu_profiler",
}
export type Categories<C extends Category = Category> =
| ((string | void) & { [" _commaSeparatedCategory"]: C; })
| C;
export function joinCategories<C extends Category>(categories: C[]): Categories<C> {
return categories.join(",") as Categories<C>;
}
export function toCategories(categories: Categories | readonly Category[]): Categories {
return Array.isArray(categories)
? joinCategories(categories)
: categories;
}
π Actual behavior
5.8 and 5.9 say narrow categories to any[] instead of readonly Category[], and the else side is still the union, leading to an error.
π Expected behavior
Categories should be the right array type, and the else branch should just be Categories.
Additional information about the issue
Noticed this while updating typescript-benchmarking past 5.7.
I think I remember an Anders PR in 5.8 that is related to this, but I can't remember what it is anymore.
π Search Terms
isarray 5.8
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.9.2#code/KYDwDg9gTgLgBAYwgOwM72MgrgWzgYQEMZgBzaATzgG8BYAKDibh2BkIBNjC4BeOAEQB9Ia3Zd2AgDQNmcGBDAAbYADdgSvoIXK1G6bOYwAlqyXHkwLQI5qFEJagB0JsxeAHGzBGCwAFKAgAM2MVKGtVAA4nHywhMECQsM85DmNUQgAjFQ4AIQoAEWAgwiwlGCFXDXdrNIzs4A4AWkyKJtsSsph2uwgHZyrzSxTmOqyc-KLO8qFYgODQ4HD+G3Txxpa2jtLypqiY33jExahPAF8GBlBIWHkKMCsiEnIoY2BUAB58OFASZA5UARiGRKFoniCoBQAHx8QxMAA+cAAFEj0K9kKQ4IjVBBjBwAJRwABkNDgAG0BHBZhAcDhCABlYBgQhQYEccEvCgCAC6AC4CABuOBnfFwrGCy70K7gaDwIJYZAIEwoOAAK1xyA50Den2+v0wAKBz0oUKRCGBLx1-PwZO5+OtFu17y+MLoXiYUDYWCgyEQjte7yc6osSOkAkJhEBWoDuqhAoYFyl9Gusrg8sVyt9CmjOrN-qtRohOvFns4KCUVGjFFt9sLlveNDFnpg3t9AEEoKyKE50h2u3njTHRe65HAAPxqjU594DovvYej5j882DnXx+iJoA
π» Code
π Actual behavior
5.8 and 5.9 say narrow
categoriestoany[]instead ofreadonly Category[], and the else side is still the union, leading to an error.π Expected behavior
Categories should be the right array type, and the else branch should just be
Categories.Additional information about the issue
Noticed this while updating typescript-benchmarking past 5.7.
I think I remember an Anders PR in 5.8 that is related to this, but I can't remember what it is anymore.