Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
20d8a94
Remove check narrowing only certain types, add test showing issues wi…
weswigham Feb 25, 2016
a2feb0e
string literal case test
weswigham Mar 11, 2016
92bf91d
Reconcile fix with CFA work
weswigham Apr 26, 2016
73d4aae
Defaultable -> NotNarrowable to align with use
weswigham Apr 26, 2016
70733da
Missed a defaultable in comments
weswigham Apr 26, 2016
a80529b
Add test for narrowing to unions of string literals
weswigham Apr 26, 2016
d111a0f
Merge branch 'master' into narrow-all-types
sandersn Jun 1, 2016
9a620bf
Actually merge from master
sandersn Jun 1, 2016
0e96c5e
Run fixupParentReferences when parsing isolated jsDocComment
zhengbli Jun 2, 2016
92177be
initial revision of unit test support for project system in tsserver
vladima Jun 2, 2016
2517238
Add non-widening forms of null and undefined
ahejlsberg Jun 2, 2016
5f3f2d3
Create separate control flows for property declarations with initiali…
ahejlsberg Jun 2, 2016
706683d
Add regression test
ahejlsberg Jun 2, 2016
9f087cb
Merge pull request #8941 from Microsoft/controlFlowPropertyDeclarations
ahejlsberg Jun 2, 2016
20bab14
Add tests
ahejlsberg Jun 2, 2016
ef0f6c8
Merge pull request #7235 from weswigham/narrow-all-types
sandersn Jun 2, 2016
fb2df77
Remove unused variable
ahejlsberg Jun 2, 2016
7e00d7e
Merge pull request #8931 from Microsoft/tsserver-projectsystem-tests
vladima Jun 2, 2016
d41ac8a
Add null check and CR feedback
zhengbli Jun 2, 2016
fc3e040
Revert "Merge pull request #7235 from weswigham/narrow-all-types"
sandersn Jun 2, 2016
e2a1a78
reuse the fixupParentReferences function
zhengbli Jun 2, 2016
24f15a4
Merge pull request #8946 from Microsoft/revert-narrow-all-types
sandersn Jun 2, 2016
131f759
Merge pull request #8930 from zhengbli/i8676
zhengbli Jun 2, 2016
3853555
Merge pull request #8944 from Microsoft/reviseWidening
ahejlsberg Jun 2, 2016
3183068
Merge branch 'master' into transforms_mergemaster
Jun 3, 2016
8012ff1
Fix up error from merging with master
Jun 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for narrowing to unions of string literals
  • Loading branch information
weswigham committed Apr 26, 2016
commit a80529b9899ebe105f6e72a176f4bdf6c5eb1586
21 changes: 21 additions & 0 deletions tests/baselines/reference/typeGuardNarrowsToLiteralTypeUnion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [typeGuardNarrowsToLiteralTypeUnion.ts]
declare function isFoo(value: string) : value is ("foo" | "bar");
declare function doThis(value: "foo" | "bar"): void;
declare function doThat(value: string) : void;
let value: string;
if (isFoo(value)) {
doThis(value);
} else {
doThat(value);
}



//// [typeGuardNarrowsToLiteralTypeUnion.js]
var value;
if (isFoo(value)) {
doThis(value);
}
else {
doThat(value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
=== tests/cases/conformance/expressions/typeGuards/typeGuardNarrowsToLiteralTypeUnion.ts ===
declare function isFoo(value: string) : value is ("foo" | "bar");
>isFoo : Symbol(isFoo, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 0, 0))
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 0, 23))
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 0, 23))

declare function doThis(value: "foo" | "bar"): void;
>doThis : Symbol(doThis, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 0, 65))
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 1, 24))

declare function doThat(value: string) : void;
>doThat : Symbol(doThat, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 1, 52))
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 2, 24))

let value: string;
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 3, 3))

if (isFoo(value)) {
>isFoo : Symbol(isFoo, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 0, 0))
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 3, 3))

doThis(value);
>doThis : Symbol(doThis, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 0, 65))
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 3, 3))

} else {
doThat(value);
>doThat : Symbol(doThat, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 1, 52))
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralTypeUnion.ts, 3, 3))
}


35 changes: 35 additions & 0 deletions tests/baselines/reference/typeGuardNarrowsToLiteralTypeUnion.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
=== tests/cases/conformance/expressions/typeGuards/typeGuardNarrowsToLiteralTypeUnion.ts ===
declare function isFoo(value: string) : value is ("foo" | "bar");
>isFoo : (value: string) => value is "foo" | "bar"
>value : string
>value : any

declare function doThis(value: "foo" | "bar"): void;
>doThis : (value: "foo" | "bar") => void
>value : "foo" | "bar"

declare function doThat(value: string) : void;
>doThat : (value: string) => void
>value : string

let value: string;
>value : string

if (isFoo(value)) {
>isFoo(value) : boolean
>isFoo : (value: string) => value is "foo" | "bar"
>value : string

doThis(value);
>doThis(value) : void
>doThis : (value: "foo" | "bar") => void
>value : "foo" | "bar"

} else {
doThat(value);
>doThat(value) : void
>doThat : (value: string) => void
>value : string
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare function isFoo(value: string) : value is ("foo" | "bar");
declare function doThis(value: "foo" | "bar"): void;
declare function doThat(value: string) : void;
let value: string;
if (isFoo(value)) {
doThis(value);
} else {
doThat(value);
}