Addressing CR feedback
This commit is contained in:
parent
91b97009f0
commit
df544a687c
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue