mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 07:29:16 -05:00
Merge branch 'master' into use-common-directory-for-out
This commit is contained in:
37
tests/baselines/reference/typeGuardInClass.js
Normal file
37
tests/baselines/reference/typeGuardInClass.js
Normal file
@@ -0,0 +1,37 @@
|
||||
//// [typeGuardInClass.ts]
|
||||
let x: string | number;
|
||||
|
||||
if (typeof x === "string") {
|
||||
let n = class {
|
||||
constructor() {
|
||||
let y: string = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
let m = class {
|
||||
constructor() {
|
||||
let y: number = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [typeGuardInClass.js]
|
||||
var x;
|
||||
if (typeof x === "string") {
|
||||
var n = (function () {
|
||||
function class_1() {
|
||||
var y = x;
|
||||
}
|
||||
return class_1;
|
||||
})();
|
||||
}
|
||||
else {
|
||||
var m = (function () {
|
||||
function class_2() {
|
||||
var y = x;
|
||||
}
|
||||
return class_2;
|
||||
})();
|
||||
}
|
||||
29
tests/baselines/reference/typeGuardInClass.symbols
Normal file
29
tests/baselines/reference/typeGuardInClass.symbols
Normal file
@@ -0,0 +1,29 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardInClass.ts ===
|
||||
let x: string | number;
|
||||
>x : Symbol(x, Decl(typeGuardInClass.ts, 0, 3))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(typeGuardInClass.ts, 0, 3))
|
||||
|
||||
let n = class {
|
||||
>n : Symbol(n, Decl(typeGuardInClass.ts, 3, 7))
|
||||
|
||||
constructor() {
|
||||
let y: string = x;
|
||||
>y : Symbol(y, Decl(typeGuardInClass.ts, 5, 15))
|
||||
>x : Symbol(x, Decl(typeGuardInClass.ts, 0, 3))
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
let m = class {
|
||||
>m : Symbol(m, Decl(typeGuardInClass.ts, 10, 7))
|
||||
|
||||
constructor() {
|
||||
let y: number = x;
|
||||
>y : Symbol(y, Decl(typeGuardInClass.ts, 12, 15))
|
||||
>x : Symbol(x, Decl(typeGuardInClass.ts, 0, 3))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
34
tests/baselines/reference/typeGuardInClass.types
Normal file
34
tests/baselines/reference/typeGuardInClass.types
Normal file
@@ -0,0 +1,34 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardInClass.ts ===
|
||||
let x: string | number;
|
||||
>x : string | number
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | number
|
||||
>"string" : string
|
||||
|
||||
let n = class {
|
||||
>n : typeof (Anonymous class)
|
||||
>class { constructor() { let y: string = x; } } : typeof (Anonymous class)
|
||||
|
||||
constructor() {
|
||||
let y: string = x;
|
||||
>y : string
|
||||
>x : string
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
let m = class {
|
||||
>m : typeof (Anonymous class)
|
||||
>class { constructor() { let y: number = x; } } : typeof (Anonymous class)
|
||||
|
||||
constructor() {
|
||||
let y: number = x;
|
||||
>y : number
|
||||
>x : number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ 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
|
||||
// Type guards affect nested function expressions and 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
|
||||
var z = x; // string
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,12 +121,12 @@ function foo4(x) {
|
||||
: x.toString(); // number
|
||||
})(x); // x here is narrowed to number | boolean
|
||||
}
|
||||
// Type guards affect nested function expressions, but not nested function declarations
|
||||
// Type guards affect nested function expressions and 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 z = x; // string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ function foo4(x: number | string | boolean) {
|
||||
})(x); // x here is narrowed to number | boolean
|
||||
>x : Symbol(x, Decl(typeGuardsInFunctionAndModuleBlock.ts, 32, 14))
|
||||
}
|
||||
// Type guards affect nested function expressions, but not nested function declarations
|
||||
// Type guards affect nested function expressions and nested function declarations
|
||||
function foo5(x: number | string | boolean) {
|
||||
>foo5 : Symbol(foo5, Decl(typeGuardsInFunctionAndModuleBlock.ts, 41, 1))
|
||||
>x : Symbol(x, Decl(typeGuardsInFunctionAndModuleBlock.ts, 43, 14))
|
||||
@@ -145,7 +145,7 @@ function foo5(x: number | string | boolean) {
|
||||
function foo() {
|
||||
>foo : Symbol(foo, Decl(typeGuardsInFunctionAndModuleBlock.ts, 45, 18))
|
||||
|
||||
var z = x; // number | string | boolean, type guard has no effect
|
||||
var z = x; // string
|
||||
>z : Symbol(z, Decl(typeGuardsInFunctionAndModuleBlock.ts, 47, 15))
|
||||
>x : Symbol(x, Decl(typeGuardsInFunctionAndModuleBlock.ts, 43, 14))
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ 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
|
||||
// Type guards affect nested function expressions and nested function declarations
|
||||
function foo5(x: number | string | boolean) {
|
||||
>foo5 : (x: number | string | boolean) => void
|
||||
>x : number | string | boolean
|
||||
@@ -199,9 +199,9 @@ function foo5(x: number | string | boolean) {
|
||||
function foo() {
|
||||
>foo : () => void
|
||||
|
||||
var z = x; // number | string | boolean, type guard has no effect
|
||||
>z : number | string | boolean
|
||||
>x : number | string | boolean
|
||||
var z = x; // string
|
||||
>z : string
|
||||
>x : string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
let x: string | number;
|
||||
|
||||
if (typeof x === "string") {
|
||||
let n = class {
|
||||
constructor() {
|
||||
let y: string = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
let m = class {
|
||||
constructor() {
|
||||
let y: number = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,12 +40,12 @@ 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
|
||||
// Type guards affect nested function expressions and 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
|
||||
var z = x; // string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user