type Input = string | number
function toString(x: Input): string {
return typeof x === 'string' ? x : x.toString()
}A union type A | B accepts either type; narrowing with typeof enables type-specific operations.
Challenge: Implement parseValue(input) that converts a string to its native JS type:
'true' β true, 'false' β falsenumberstringparseValue('42') // β 42
parseValue('true') // β true