Skip to content

Commit df544a6

Browse files
committed
Addressing CR feedback
1 parent 91b9700 commit df544a6

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ function foo4(x: number | string | boolean) {
4141
: x.toString(); // number
4242
})(x); // x here is narrowed to number | boolean
4343
}
44+
// Type guards affect nested function expressions, but not nested function declarations
45+
function foo5(x: number | string | boolean) {
46+
if (typeof x === "string") {
47+
var y = x; // string;
48+
function foo() {
49+
var z = x; // number | string | boolean, type guard has no effect
50+
}
51+
}
52+
}
4453
module m {
4554
var x: number | string | boolean;
4655
module m2 {
@@ -96,6 +105,15 @@ function foo4(x) {
96105
return typeof x === "boolean" ? x.toString() : x.toString(); // number
97106
})(x); // x here is narrowed to number | boolean
98107
}
108+
// Type guards affect nested function expressions, but not nested function declarations
109+
function foo5(x) {
110+
if (typeof x === "string") {
111+
var y = x; // string;
112+
function foo() {
113+
var z = x; // number | string | boolean, type guard has no effect
114+
}
115+
}
116+
}
99117
var m;
100118
(function (m) {
101119
var x;

tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,29 @@ function foo4(x: number | string | boolean) {
173173
})(x); // x here is narrowed to number | boolean
174174
>x : number | boolean
175175
}
176+
// Type guards affect nested function expressions, but not nested function declarations
177+
function foo5(x: number | string | boolean) {
178+
>foo5 : (x: string | number | boolean) => void
179+
>x : string | number | boolean
180+
181+
if (typeof x === "string") {
182+
>typeof x === "string" : boolean
183+
>typeof x : string
184+
>x : string | number | boolean
185+
186+
var y = x; // string;
187+
>y : string
188+
>x : string
189+
190+
function foo() {
191+
>foo : () => void
192+
193+
var z = x; // number | string | boolean, type guard has no effect
194+
>z : string | number | boolean
195+
>x : string | number | boolean
196+
}
197+
}
198+
}
176199
module m {
177200
>m : typeof m
178201

tests/cases/conformance/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ function foo4(x: number | string | boolean) {
4040
: x.toString(); // number
4141
})(x); // x here is narrowed to number | boolean
4242
}
43+
// Type guards affect nested function expressions, but not nested function declarations
44+
function foo5(x: number | string | boolean) {
45+
if (typeof x === "string") {
46+
var y = x; // string;
47+
function foo() {
48+
var z = x; // number | string | boolean, type guard has no effect
49+
}
50+
}
51+
}
4352
module m {
4453
var x: number | string | boolean;
4554
module m2 {

0 commit comments

Comments
 (0)