typeof narrows primitive unions at runtime. After a typeof value === 'string' check, you can safely use string-only members like .length. If it’s a number, you can use it directly.
function describe(v: string | number) {
if (typeof v === "string") return "text:" + v.length;
return "num:" + v;
}
Return a number so tests can compare easily, and cover an empty string as an edge case.
Compute a size number from a string | number.