-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose EmptyT as type annotation
empty
Summary: A few people on GitHub have come up with hacky ways to mimic this type, like `string & number`, but they aren't quite the same. I think the utility here is pretty marginal, but I'm confident that exposing this type is at least neutral and should not have any negative effects. Until reachability lands, `empty` can verify that Flow is convinced of exhaustiveness. ``` function exhaust(x: number | string) { if (typeof x === "number") { // do stuff } else if (typeof x === "string") { // do different stuff } else { // only true if we handled all cases (x: empty); } } ``` I considered that `empty` might confound/confuse poly instantiation, for example by satisfying a generic type in a way that breaks parametricity. Well, kind of, but you need to use `declare var` ``` function f<T>(): T { declare var x: empty; return x; } ``` and of course the same trick would work with `declare var x: T`, so I think we're OK. Without `declare var`, we can devise a function that passes local inference, but is uncallable. ``` function f<T>(x: empty): T { return x; } f(); // nothing to pass... ``` Reviewed By: avikchaudhuri Differential Revision: D3979445 fbshipit-source-id: 911d70dbf7159968d70e7c56d55b9aba4df41e71
- Loading branch information
1 parent
0223ff2
commit c603505
Showing
7 changed files
with
30 additions
and
20 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
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
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 |
---|---|---|
|
@@ -152,6 +152,7 @@ and Type : sig | |
and t' = | ||
| Any | ||
| Mixed | ||
| Empty | ||
| Void | ||
| Null | ||
| Number | ||
|
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