mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 10:29:18 -05:00
Addressing CR feedback
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user