-
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.
[flow] Singleton types get a with "generalizable" field
Summary: In the following code under natural inference ``` const x1 = "a"; const o1 = {f: x1}; ``` we would like to infer ``` x1: "a" // SingletonStrT("a") o1: {f:string} // ObjT {f: StrGeneralT} ``` At the same time, an annotated version of this code: ``` const x2: "a" = "a"; const o2 = {f: x2}; ``` should yield ``` x2: "a" // SingletonStrT("a") o2: {f:"a"} // ObjT {f: SingletonStrT("a")} ``` Note the difference between `o1` and `o2`. To enable this behavior we need to be able to distinguish between the two types of `SingletonStrT` that we infer for `x1` and `x2`. The key difference is whether we should allow a `SingletonStrT` to "generalize" to `StrGeneralT`. Roughly, a string literal type is generalizable iff it does not originate from an annotation, or a value under `as const`, or `Object.freeze()`. This diff adds a field `from_annot` to `SingletonStrT`, `SingletonNumT`, etc, and populates it accordingly. This field has no impact yet in typechecking behavior. It will only be used later to inform the generalization process. Changelog: [internal] Reviewed By: SamChou19815 Differential Revision: D66659579 fbshipit-source-id: 148f2e35de53debc600d17f735dc51cbd771d190
- Loading branch information
1 parent
ae4c8c1
commit a1f78dd
Showing
20 changed files
with
235 additions
and
167 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
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
Oops, something went wrong.