-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugs for unions of type predicates
- Loading branch information
Andy Hanson
committed
Oct 6, 2017
1 parent
7001e71
commit d52812f
Showing
9 changed files
with
345 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// [typePredicatesInUnion.ts] | ||
interface A { | ||
pred(x: {}): x is boolean; | ||
} | ||
interface B { | ||
pred(x: {}): x is string; | ||
} | ||
|
||
type Or = A | B; | ||
|
||
function f(o: Or, x: {}) { | ||
if (o.pred(x)) { | ||
x; | ||
} | ||
} | ||
|
||
|
||
//// [typePredicatesInUnion.js] | ||
function f(o, x) { | ||
if (o.pred(x)) { | ||
x; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
=== tests/cases/compiler/typePredicatesInUnion.ts === | ||
interface A { | ||
>A : Symbol(A, Decl(typePredicatesInUnion.ts, 0, 0)) | ||
|
||
pred(x: {}): x is boolean; | ||
>pred : Symbol(A.pred, Decl(typePredicatesInUnion.ts, 0, 13)) | ||
>x : Symbol(x, Decl(typePredicatesInUnion.ts, 1, 9)) | ||
>x : Symbol(x, Decl(typePredicatesInUnion.ts, 1, 9)) | ||
} | ||
interface B { | ||
>B : Symbol(B, Decl(typePredicatesInUnion.ts, 2, 1)) | ||
|
||
pred(x: {}): x is string; | ||
>pred : Symbol(B.pred, Decl(typePredicatesInUnion.ts, 3, 13)) | ||
>x : Symbol(x, Decl(typePredicatesInUnion.ts, 4, 9)) | ||
>x : Symbol(x, Decl(typePredicatesInUnion.ts, 4, 9)) | ||
} | ||
|
||
type Or = A | B; | ||
>Or : Symbol(Or, Decl(typePredicatesInUnion.ts, 5, 1)) | ||
>A : Symbol(A, Decl(typePredicatesInUnion.ts, 0, 0)) | ||
>B : Symbol(B, Decl(typePredicatesInUnion.ts, 2, 1)) | ||
|
||
function f(o: Or, x: {}) { | ||
>f : Symbol(f, Decl(typePredicatesInUnion.ts, 7, 16)) | ||
>o : Symbol(o, Decl(typePredicatesInUnion.ts, 9, 11)) | ||
>Or : Symbol(Or, Decl(typePredicatesInUnion.ts, 5, 1)) | ||
>x : Symbol(x, Decl(typePredicatesInUnion.ts, 9, 17)) | ||
|
||
if (o.pred(x)) { | ||
>o.pred : Symbol(pred, Decl(typePredicatesInUnion.ts, 0, 13), Decl(typePredicatesInUnion.ts, 3, 13)) | ||
>o : Symbol(o, Decl(typePredicatesInUnion.ts, 9, 11)) | ||
>pred : Symbol(pred, Decl(typePredicatesInUnion.ts, 0, 13), Decl(typePredicatesInUnion.ts, 3, 13)) | ||
>x : Symbol(x, Decl(typePredicatesInUnion.ts, 9, 17)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(typePredicatesInUnion.ts, 9, 17)) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
=== tests/cases/compiler/typePredicatesInUnion.ts === | ||
interface A { | ||
>A : A | ||
|
||
pred(x: {}): x is boolean; | ||
>pred : (x: {}) => x is boolean | ||
>x : {} | ||
>x : any | ||
} | ||
interface B { | ||
>B : B | ||
|
||
pred(x: {}): x is string; | ||
>pred : (x: {}) => x is string | ||
>x : {} | ||
>x : any | ||
} | ||
|
||
type Or = A | B; | ||
>Or : Or | ||
>A : A | ||
>B : B | ||
|
||
function f(o: Or, x: {}) { | ||
>f : (o: Or, x: {}) => void | ||
>o : Or | ||
>Or : Or | ||
>x : {} | ||
|
||
if (o.pred(x)) { | ||
>o.pred(x) : boolean | ||
>o.pred : ((x: {}) => x is boolean) | ((x: {}) => x is string) | ||
>o : Or | ||
>pred : ((x: {}) => x is boolean) | ((x: {}) => x is string) | ||
>x : {} | ||
|
||
x; | ||
>x : string | boolean | ||
} | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/typePredicatesInUnion_noMatch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//// [typePredicatesInUnion_noMatch.ts] | ||
interface A { | ||
pred(x: {}, y: {}): x is boolean; | ||
} | ||
interface B { | ||
pred(x: {}, y: {}): y is string; | ||
} | ||
|
||
type Or = A | B; | ||
|
||
function f(o: Or, x: {}, y: {}) { | ||
if (o.pred(x, y)) { | ||
x; | ||
y; | ||
} | ||
} | ||
|
||
|
||
//// [typePredicatesInUnion_noMatch.js] | ||
function f(o, x, y) { | ||
if (o.pred(x, y)) { | ||
x; | ||
y; | ||
} | ||
} |
Oops, something went wrong.