Search code examples
javascriptfunctiontypescriptfunction-parameter

One Typescript Function Parameter - Optional Types?


I guess I'm bad at looking through documentations, because I can't figure this out:

var help = (param: string or number) => {
     return param;
}

How do I allow the help function to have a param of either a string or number?

For example:

help("string"); //returns "string"

help(123); //returns 123

Solution

  • its just an or |

    var help = (param: string | number) => { return param; }