Microsoft/TypeScript — pull request #1163 by ahejlsberg (2014-11-14 14:59:42+00:00)
Title: Fixes to type guards

Two minor fixes to type guards.

First, a fix to #1070. A type guard now has an effect only if the narrowed type is a subtype of the variable type.
```typescript
var x: string | number;
if (typeof x === "boolean") {
var b = x; // x still of type string | number
}
```
We could consider reporting an error, but I'm not sure about that.

Second, type guards now consistently affect code in nested function expressions. For example:
```typescript
function foo(x; string | number) {
if (typeof x === "string") {
var f = function() {
return x; // x of type string here
}
}
}
```
Before this change, only code in expression bodied arrow functions was affected by type guards (which was an inconsistency and a bug). In the example above, it is possible that `x` isn't of type string by the time `f` is called (because of an assignment to `x` outside the type guarded code) but it is already a fact that we don't track assignments that happen in functions called from the guarded code, and it really is inconvenient if type guards don't affect nested function expressions.