-
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.
Don't mutate literal object types during subtyping
Summary: Changelog: [errors] We will now emit new errors in places where an object literal has literal types, but doesn't have an annotation. You can usually fix these errors by adding annotations to object literals. [lib] Improved libdef for fs.readdir and fs.readdirSync for better overload resolution This behavior was introduced to catch the following cases: ``` var a = { p: 0 }; var b: { p: number | string }; // a.p <- number | string b.p = ""; (a.p : number); // at runtime, a.p is a string due to aliasing ``` or, similarly with optional properties: ``` var a = { p: 0 }; var b: { p?: number } = a; // a.p <- optional number b.p = undefined; (a.p : number); // at runtime, a.p is void due to aliasing ``` While this does introduce some measure of safety in these examples, it also introduces order dependence to constraints, which violates a fundamental assumption of the type checker. LTI will not require this hacky approximation. Instead, we will rely on contextual typing to provide precise inference for literal types and require annotations where context is unavailable. Removing this behavior now will remove some safety, but unblocks development of LTI. Part of LTI changes the order in which constraints are visited by the solver, which causes spurious errors due to this change. Reviewed By: samwgoldman Differential Revision: D37501336 fbshipit-source-id: 382de86b99d33e3e7fdc75b2260a405e513a5ec5
- Loading branch information
1 parent
b026691
commit 0b9c9bb
Showing
14 changed files
with
208 additions
and
924 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
Oops, something went wrong.