Question from the Angular 4 (legacy) test

Fix the error: Argument of type 'true' is not assignable to parameter of type 'string | number'

Hard

Here is the following code:

function bar(x: string | number) : number {
    if ('number' === typeof x) {
        return 0;
    }
    return 1;
}
console.log(bar(4), bar('8'), bar('a'), bar(true));

What will this code produce?

Author: Mathieu RobinStatus: PublishedQuestion passed 473 times
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!