Deno types

Union types

function add(a: any, b: any) {
    if (typeof a === 'number' && typeof b === 'number') {
        return a + b;
    }
    if (typeof a === 'string' && typeof b === 'string') {
        return a.concat(b);
    }
    throw new Error('Parameters must be numbers or strings');
}
add(true, false);
evalmachine.<anonymous>:10
    throw new Error('Parameters must be numbers or strings');
    ^

Error: Parameters must be numbers or strings
    at Proxy.add (evalmachine.<anonymous>:10:11)
    at evalmachine.<anonymous>:3:30
    at evalmachine.<anonymous>:5:3
    at sigintHandlersWrap (node:vm:271:12)
    at Script.runInThisContext (node:vm:129:14)
    at Object.runInThisContext (node:vm:308:38)
    at Object.execute (/Users/rui/.asdf/installs/nodejs/15.11.0/.npm/lib/node_modules/tslab/dist/executor.js:162:38)
    at JupyterHandlerImpl.handleExecuteImpl (/Users/rui/.asdf/installs/nodejs/15.11.0/.npm/lib/node_modules/tslab/dist/jupyter.js:219:38)
    at /Users/rui/.asdf/installs/nodejs/15.11.0/.npm/lib/node_modules/tslab/dist/jupyter.js:177:57
    at async JupyterHandlerImpl.handleExecute (/Users/rui/.asdf/installs/nodejs/15.11.0/.npm/lib/node_modules/tslab/dist/jupyter.js:177:21)
function add(a: number | string, b: number | string) {
    if (typeof a === 'number' && typeof b === 'number') {
        return a + b;
    }
    if (typeof a === 'string' && typeof b === 'string') {
        return a.concat(b);
    }
    throw new Error('Parameters must be numbers or strings');
}
add(true, false);
1:5 - Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
add(1, 3);
4
add('a', 'b');
ab