mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Remove check narrowing only certain types, add test showing issues with this
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
//// [typeGuardNarrowsPrimitiveIntersection.ts]
|
||||
type Tag = {__tag: any};
|
||||
declare function isNonBlank(value: string) : value is (string & Tag);
|
||||
declare function doThis(value: string & Tag): void;
|
||||
declare function doThat(value: string) : void;
|
||||
let value: string;
|
||||
if (isNonBlank(value)) {
|
||||
doThis(value);
|
||||
} else {
|
||||
doThat(value);
|
||||
}
|
||||
|
||||
|
||||
const enum Tag2 {}
|
||||
declare function isNonBlank2(value: string) : value is (string & Tag2);
|
||||
declare function doThis2(value: string & Tag2): void;
|
||||
declare function doThat2(value: string) : void;
|
||||
if (isNonBlank2(value)) {
|
||||
doThis2(value);
|
||||
} else {
|
||||
doThat2(value);
|
||||
}
|
||||
|
||||
|
||||
//// [typeGuardNarrowsPrimitiveIntersection.js]
|
||||
var value;
|
||||
if (isNonBlank(value)) {
|
||||
doThis(value);
|
||||
}
|
||||
else {
|
||||
doThat(value);
|
||||
}
|
||||
if (isNonBlank2(value)) {
|
||||
doThis2(value);
|
||||
}
|
||||
else {
|
||||
doThat2(value);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardNarrowsPrimitiveIntersection.ts ===
|
||||
type Tag = {__tag: any};
|
||||
>Tag : Symbol(Tag, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 0, 0))
|
||||
>__tag : Symbol(__tag, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 0, 12))
|
||||
|
||||
declare function isNonBlank(value: string) : value is (string & Tag);
|
||||
>isNonBlank : Symbol(isNonBlank, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 0, 24))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 1, 28))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 1, 28))
|
||||
>Tag : Symbol(Tag, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 0, 0))
|
||||
|
||||
declare function doThis(value: string & Tag): void;
|
||||
>doThis : Symbol(doThis, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 1, 69))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 2, 24))
|
||||
>Tag : Symbol(Tag, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 0, 0))
|
||||
|
||||
declare function doThat(value: string) : void;
|
||||
>doThat : Symbol(doThat, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 2, 51))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 3, 24))
|
||||
|
||||
let value: string;
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 4, 3))
|
||||
|
||||
if (isNonBlank(value)) {
|
||||
>isNonBlank : Symbol(isNonBlank, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 0, 24))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 4, 3))
|
||||
|
||||
doThis(value);
|
||||
>doThis : Symbol(doThis, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 1, 69))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 4, 3))
|
||||
|
||||
} else {
|
||||
doThat(value);
|
||||
>doThat : Symbol(doThat, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 2, 51))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 4, 3))
|
||||
}
|
||||
|
||||
|
||||
const enum Tag2 {}
|
||||
>Tag2 : Symbol(Tag2, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 9, 1))
|
||||
|
||||
declare function isNonBlank2(value: string) : value is (string & Tag2);
|
||||
>isNonBlank2 : Symbol(isNonBlank2, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 12, 18))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 13, 29))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 13, 29))
|
||||
>Tag2 : Symbol(Tag2, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 9, 1))
|
||||
|
||||
declare function doThis2(value: string & Tag2): void;
|
||||
>doThis2 : Symbol(doThis2, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 13, 71))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 14, 25))
|
||||
>Tag2 : Symbol(Tag2, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 9, 1))
|
||||
|
||||
declare function doThat2(value: string) : void;
|
||||
>doThat2 : Symbol(doThat2, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 14, 53))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 15, 25))
|
||||
|
||||
if (isNonBlank2(value)) {
|
||||
>isNonBlank2 : Symbol(isNonBlank2, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 12, 18))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 4, 3))
|
||||
|
||||
doThis2(value);
|
||||
>doThis2 : Symbol(doThis2, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 13, 71))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 4, 3))
|
||||
|
||||
} else {
|
||||
doThat2(value);
|
||||
>doThat2 : Symbol(doThat2, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 14, 53))
|
||||
>value : Symbol(value, Decl(typeGuardNarrowsPrimitiveIntersection.ts, 4, 3))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/typeGuardNarrowsPrimitiveIntersection.ts ===
|
||||
type Tag = {__tag: any};
|
||||
>Tag : { __tag: any; }
|
||||
>__tag : any
|
||||
|
||||
declare function isNonBlank(value: string) : value is (string & Tag);
|
||||
>isNonBlank : (value: string) => value is string & { __tag: any; }
|
||||
>value : string
|
||||
>value : any
|
||||
>Tag : { __tag: any; }
|
||||
|
||||
declare function doThis(value: string & Tag): void;
|
||||
>doThis : (value: string & { __tag: any; }) => void
|
||||
>value : string & { __tag: any; }
|
||||
>Tag : { __tag: any; }
|
||||
|
||||
declare function doThat(value: string) : void;
|
||||
>doThat : (value: string) => void
|
||||
>value : string
|
||||
|
||||
let value: string;
|
||||
>value : string
|
||||
|
||||
if (isNonBlank(value)) {
|
||||
>isNonBlank(value) : boolean
|
||||
>isNonBlank : (value: string) => value is string & { __tag: any; }
|
||||
>value : string
|
||||
|
||||
doThis(value);
|
||||
>doThis(value) : void
|
||||
>doThis : (value: string & { __tag: any; }) => void
|
||||
>value : string & { __tag: any; }
|
||||
|
||||
} else {
|
||||
doThat(value);
|
||||
>doThat(value) : void
|
||||
>doThat : (value: string) => void
|
||||
>value : string
|
||||
}
|
||||
|
||||
|
||||
const enum Tag2 {}
|
||||
>Tag2 : Tag2
|
||||
|
||||
declare function isNonBlank2(value: string) : value is (string & Tag2);
|
||||
>isNonBlank2 : (value: string) => value is string & Tag2
|
||||
>value : string
|
||||
>value : any
|
||||
>Tag2 : Tag2
|
||||
|
||||
declare function doThis2(value: string & Tag2): void;
|
||||
>doThis2 : (value: string & Tag2) => void
|
||||
>value : string & Tag2
|
||||
>Tag2 : Tag2
|
||||
|
||||
declare function doThat2(value: string) : void;
|
||||
>doThat2 : (value: string) => void
|
||||
>value : string
|
||||
|
||||
if (isNonBlank2(value)) {
|
||||
>isNonBlank2(value) : boolean
|
||||
>isNonBlank2 : (value: string) => value is string & Tag2
|
||||
>value : string
|
||||
|
||||
doThis2(value);
|
||||
>doThis2(value) : void
|
||||
>doThis2 : (value: string & Tag2) => void
|
||||
>value : string & Tag2
|
||||
|
||||
} else {
|
||||
doThat2(value);
|
||||
>doThat2(value) : void
|
||||
>doThat2 : (value: string) => void
|
||||
>value : string
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
type Tag = {__tag: any};
|
||||
declare function isNonBlank(value: string) : value is (string & Tag);
|
||||
declare function doThis(value: string & Tag): void;
|
||||
declare function doThat(value: string) : void;
|
||||
let value: string;
|
||||
if (isNonBlank(value)) {
|
||||
doThis(value);
|
||||
} else {
|
||||
doThat(value);
|
||||
}
|
||||
|
||||
|
||||
const enum Tag2 {}
|
||||
declare function isNonBlank2(value: string) : value is (string & Tag2);
|
||||
declare function doThis2(value: string & Tag2): void;
|
||||
declare function doThat2(value: string) : void;
|
||||
if (isNonBlank2(value)) {
|
||||
doThis2(value);
|
||||
} else {
|
||||
doThat2(value);
|
||||
}
|
||||
Reference in New Issue
Block a user