Addressing CR feedback

This commit is contained in:
Anders Hejlsberg 2014-11-14 13:36:09 -08:00
parent 91b97009f0
commit df544a687c
3 changed files with 50 additions and 0 deletions

View file

@ -41,6 +41,15 @@ function foo4(x: number | string | boolean) {
: x.toString(); // number
})(x); // x here is narrowed to number | boolean
}
// Type guards affect nested function expressions, but not nested function declarations
function foo5(x: number | string | boolean) {
if (typeof x === "string") {
var y = x; // string;
function foo() {
var z = x; // number | string | boolean, type guard has no effect
}
}
}
module m {
var x: number | string | boolean;
module m2 {
@ -96,6 +105,15 @@ function foo4(x) {
return typeof x === "boolean" ? x.toString() : x.toString(); // number
})(x); // x here is narrowed to number | boolean
}
// Type guards affect nested function expressions, but not nested function declarations
function foo5(x) {
if (typeof x === "string") {
var y = x; // string;
function foo() {
var z = x; // number | string | boolean, type guard has no effect
}
}
}
var m;
(function (m) {
var x;

View file

@ -173,6 +173,29 @@ function foo4(x: number | string | boolean) {
})(x); // x here is narrowed to number | boolean
>x : number | boolean
}
// Type guards affect nested function expressions, but not nested function declarations
function foo5(x: number | string | boolean) {
>foo5 : (x: string | number | boolean) => void
>x : string | number | boolean
if (typeof x === "string") {
>typeof x === "string" : boolean
>typeof x : string
>x : string | number | boolean
var y = x; // string;
>y : string
>x : string
function foo() {
>foo : () => void
var z = x; // number | string | boolean, type guard has no effect
>z : string | number | boolean
>x : string | number | boolean
}
}
}
module m {
>m : typeof m

View file

@ -40,6 +40,15 @@ function foo4(x: number | string | boolean) {
: x.toString(); // number
})(x); // x here is narrowed to number | boolean
}
// Type guards affect nested function expressions, but not nested function declarations
function foo5(x: number | string | boolean) {
if (typeof x === "string") {
var y = x; // string;
function foo() {
var z = x; // number | string | boolean, type guard has no effect
}
}
}
module m {
var x: number | string | boolean;
module m2 {