# Function return number if params are number; string if any is not

## Issue

Here is my case:

``````/**
* - accepts `a` parameter of type string or number
* - accepts `b` parameter of type string or number
* - returns type number when both `a` and `b` are of type number
* - returns type string when at least one param is of type string
*
* ⚠️ There is no need to modyfy the body of the function.
*/

if (typeof a === 'number' && typeof b === 'number') {
return a + b;
}

return String(a) + String(b);
}

////////////////////////////////////////////////////////////////////////////////
////////////////////   TEST CASES - look but don't modify   ////////////////////
////////////////////////////////////////////////////////////////////////////////

type cases = [
Expect<Equal<typeof sumA, number>>,
Expect<Equal<typeof sumB, string>>,
Expect<Equal<typeof sumC, string>>,
Expect<Equal<typeof sumD, string>>,
]

type Expect<T extends true> = T
type Equal<X, Y> =
(<T>() => T extends X ? 1 : 2) extends
(<T>() => T extends Y ? 1 : 2) ? true : false
``````

No matter what I do (conditional return, type aliases) it does not allow me to pass through Expect cases.

Does anyone have an idea how to solve it?

Playground

## Solution

``````function add(a: number, b: number): number
function add(a: string | number, b: string | number): string
function add(a: string | number, b: string | number): string | number {
if (typeof a === 'number' && typeof b === 'number') {
return a + b;
}

return String(a) + String(b);
}
``````

Playground