I am attempting to create a type that can be either string | number
or just number
, but never solely string
. I made an attempt below, but it seems like the string | number
case is reduced to just number
. Is there a way to achieve this without such reduction?
type StringOrNumberOrJustNumber<T extends string | number = string | number>
= T extends number ? T : never;
// Expected output: "string | number"
type StringOrNumber = StringOrNumberOrJustNumber<string | number>;
// Desired output: "never" (or an error)
type JustString = StringOrNumberOrJustNumber<string>;
// Expected output: "number"
type JustNumber = StringOrNumberOrJustNumber<number>;