Is this binary search in TypeScript correct?
That looks jolly complicated.  If you haven't read it, look for Jon Bentley's Programming Pearls article on binary search.  Here's my version:

var bSearch = &lt;T&gt;(xs: T[], x: T, cmp: (p: T, q: T) =&gt; number): number =&gt; {
    var bot = 0;
    var top = xs.length;
    while (bot &lt; top) { // If x is in xs, it's somewhere in xs[bot..top).
        var mid = Math.floor((bot + top) / 2);
        var c = cmp(xs[mid], x);
        if (c === 0) return mid;
        if (c &lt; 0) bot = mid + 1;
        if (0 &lt; c) top = mid; 
    }
    return -1;
}

var cmp = (p: number, q: number) =&gt; p - q;

console.log(bSearch([], 3, cmp) === -1);
console.log(bSearch([3], 3, cmp) === 0);
console.log(bSearch([1, 3], 3, cmp) === 1);
console.log(bSearch([3, 4], 3, cmp) === 0);
console.log(bSearch([3, 3], 3, cmp) !== -1);
console.log(bSearch([1, 2, 3], 3, cmp) === 2);
console.log(bSearch([1, 3, 4], 3, cmp) === 1);
console.log(bSearch([3, 4, 5], 3, cmp) === 0);
console.log(bSearch([4, 5, 6], 3, cmp) === -1);