A conditional type chooses one type when a generic value matches a shape and another type otherwise.

Conditional Label Type

label_type.ts
type ValueLabel<T> = T extends number ? "number" : "text";

function labelValue<T extends number | string>(value: T): ValueLabel<T> {
    return (typeof value === "number" ? "number" : "text") as ValueLabel<T>;
}

const useNumber: boolean = ;
const value: number | string = useNumber ? 12 : "trace";
const label: "number" | "text" = labelValue(value);

console.log(`${label}:${value}`);
type ValueLabel<T> = T extends number ? "number" : "text";

function labelValue<T extends number | string>(value: T): ValueLabel<T> {
    return (typeof value === "number" ? "number" : "text") as ValueLabel<T>;
}

const useNumber: boolean = ;
const value: number | string = useNumber ? 12 : "trace";
const label: "number" | "text" = labelValue(value);

console.log(`${label}:${value}`);
conditional type `T extends U ? A : B` selects `A` when `T` fits `U`; otherwise it selects `B`.