Mix and match types in a Typescript function
Typescript provides a convenient way to accept different types of arguments for a function, or to combine multiple types into one super type. Consider this example - function printThis(a: string) { return typeof a; } console.log(printThis("hello")); // string This function is fine if we want to return the input string for some strange reason. But, what if we want to generalise that function to - say, numbers? Union type In Typescript we can simply specify the argument as being string or a number using what is called “union type”. ...