mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
symbols in type guards
This commit is contained in:
parent
9f39a5388a
commit
df826de042
@ -4767,7 +4767,7 @@ module ts {
|
||||
if (assumeTrue) {
|
||||
// Assumed result is true. If check was not for a primitive type, remove all primitive types
|
||||
if (!typeInfo) {
|
||||
return removeTypesFromUnionType(type, /*typeKind*/ TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.Boolean, /*isOfTypeKind*/ true);
|
||||
return removeTypesFromUnionType(type, /*typeKind*/ TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.Boolean | TypeFlags.ESSymbol, /*isOfTypeKind*/ true);
|
||||
}
|
||||
// Check was for a primitive type, return that primitive type if it is a subtype
|
||||
if (isTypeSubtypeOf(typeInfo.type, type)) {
|
||||
|
||||
21
tests/baselines/reference/symbolType17.js
Normal file
21
tests/baselines/reference/symbolType17.js
Normal file
@ -0,0 +1,21 @@
|
||||
//// [symbolType17.ts]
|
||||
interface Foo { prop }
|
||||
var x: symbol | Foo;
|
||||
|
||||
x;
|
||||
if (typeof x === "symbol") {
|
||||
x;
|
||||
}
|
||||
else {
|
||||
x;
|
||||
}
|
||||
|
||||
//// [symbolType17.js]
|
||||
var x;
|
||||
x;
|
||||
if (typeof x === "symbol") {
|
||||
x;
|
||||
}
|
||||
else {
|
||||
x;
|
||||
}
|
||||
24
tests/baselines/reference/symbolType17.types
Normal file
24
tests/baselines/reference/symbolType17.types
Normal file
@ -0,0 +1,24 @@
|
||||
=== tests/cases/conformance/es6/Symbols/symbolType17.ts ===
|
||||
interface Foo { prop }
|
||||
>Foo : Foo
|
||||
>prop : any
|
||||
|
||||
var x: symbol | Foo;
|
||||
>x : symbol | Foo
|
||||
>Foo : Foo
|
||||
|
||||
x;
|
||||
>x : symbol | Foo
|
||||
|
||||
if (typeof x === "symbol") {
|
||||
>typeof x === "symbol" : boolean
|
||||
>typeof x : string
|
||||
>x : symbol | Foo
|
||||
|
||||
x;
|
||||
>x : symbol
|
||||
}
|
||||
else {
|
||||
x;
|
||||
>x : Foo
|
||||
}
|
||||
21
tests/baselines/reference/symbolType18.js
Normal file
21
tests/baselines/reference/symbolType18.js
Normal file
@ -0,0 +1,21 @@
|
||||
//// [symbolType18.ts]
|
||||
interface Foo { prop }
|
||||
var x: symbol | Foo;
|
||||
|
||||
x;
|
||||
if (typeof x === "object") {
|
||||
x;
|
||||
}
|
||||
else {
|
||||
x;
|
||||
}
|
||||
|
||||
//// [symbolType18.js]
|
||||
var x;
|
||||
x;
|
||||
if (typeof x === "object") {
|
||||
x;
|
||||
}
|
||||
else {
|
||||
x;
|
||||
}
|
||||
24
tests/baselines/reference/symbolType18.types
Normal file
24
tests/baselines/reference/symbolType18.types
Normal file
@ -0,0 +1,24 @@
|
||||
=== tests/cases/conformance/es6/Symbols/symbolType18.ts ===
|
||||
interface Foo { prop }
|
||||
>Foo : Foo
|
||||
>prop : any
|
||||
|
||||
var x: symbol | Foo;
|
||||
>x : symbol | Foo
|
||||
>Foo : Foo
|
||||
|
||||
x;
|
||||
>x : symbol | Foo
|
||||
|
||||
if (typeof x === "object") {
|
||||
>typeof x === "object" : boolean
|
||||
>typeof x : string
|
||||
>x : symbol | Foo
|
||||
|
||||
x;
|
||||
>x : Foo
|
||||
}
|
||||
else {
|
||||
x;
|
||||
>x : symbol | Foo
|
||||
}
|
||||
24
tests/baselines/reference/symbolType19.js
Normal file
24
tests/baselines/reference/symbolType19.js
Normal file
@ -0,0 +1,24 @@
|
||||
//// [symbolType19.ts]
|
||||
enum E { }
|
||||
var x: symbol | E;
|
||||
|
||||
x;
|
||||
if (typeof x === "number") {
|
||||
x;
|
||||
}
|
||||
else {
|
||||
x;
|
||||
}
|
||||
|
||||
//// [symbolType19.js]
|
||||
var E;
|
||||
(function (E) {
|
||||
})(E || (E = {}));
|
||||
var x;
|
||||
x;
|
||||
if (typeof x === "number") {
|
||||
x;
|
||||
}
|
||||
else {
|
||||
x;
|
||||
}
|
||||
23
tests/baselines/reference/symbolType19.types
Normal file
23
tests/baselines/reference/symbolType19.types
Normal file
@ -0,0 +1,23 @@
|
||||
=== tests/cases/conformance/es6/Symbols/symbolType19.ts ===
|
||||
enum E { }
|
||||
>E : E
|
||||
|
||||
var x: symbol | E;
|
||||
>x : symbol | E
|
||||
>E : E
|
||||
|
||||
x;
|
||||
>x : symbol | E
|
||||
|
||||
if (typeof x === "number") {
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : symbol | E
|
||||
|
||||
x;
|
||||
>x : E
|
||||
}
|
||||
else {
|
||||
x;
|
||||
>x : symbol
|
||||
}
|
||||
11
tests/cases/conformance/es6/Symbols/symbolType17.ts
Normal file
11
tests/cases/conformance/es6/Symbols/symbolType17.ts
Normal file
@ -0,0 +1,11 @@
|
||||
//@target: ES6
|
||||
interface Foo { prop }
|
||||
var x: symbol | Foo;
|
||||
|
||||
x;
|
||||
if (typeof x === "symbol") {
|
||||
x;
|
||||
}
|
||||
else {
|
||||
x;
|
||||
}
|
||||
11
tests/cases/conformance/es6/Symbols/symbolType18.ts
Normal file
11
tests/cases/conformance/es6/Symbols/symbolType18.ts
Normal file
@ -0,0 +1,11 @@
|
||||
//@target: ES6
|
||||
interface Foo { prop }
|
||||
var x: symbol | Foo;
|
||||
|
||||
x;
|
||||
if (typeof x === "object") {
|
||||
x;
|
||||
}
|
||||
else {
|
||||
x;
|
||||
}
|
||||
11
tests/cases/conformance/es6/Symbols/symbolType19.ts
Normal file
11
tests/cases/conformance/es6/Symbols/symbolType19.ts
Normal file
@ -0,0 +1,11 @@
|
||||
//@target: ES6
|
||||
enum E { }
|
||||
var x: symbol | E;
|
||||
|
||||
x;
|
||||
if (typeof x === "number") {
|
||||
x;
|
||||
}
|
||||
else {
|
||||
x;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user