-
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.
when promoting primitives on method calls, also promote the method ca…
…ll's this argument Summary: When calling methods on primitive types like arrays, number or strings that are present in their wrapper object, we promote the primitive to an instance of the wrapper class. We do not, however, similarly promote the `this` argument to the method call itself. This did not matter before `this` parameters were more strict than simply `any`, however, in a world where the `this` parameter of a method is the type of the class, we need to correctly promote the primitive `this` argument to an instance of its wrapper object as well. This also has the nice side effect of improving type inference for array methods, which would infer a union with `any` as a result of the `any`-type of the method's call. By replacing this with the applied instance of the array wrapper class, we can produce a narrower type. Reviewed By: mvitousek Differential Revision: D24788676 fbshipit-source-id: 16b7495d3c7b259564c375f942983c3c1ae7d881
- Loading branch information
1 parent
81f2bfe
commit 215ac06
Showing
6 changed files
with
64 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @flow | ||
|
||
declare var x: ?{ | ||
a: $ReadOnlyArray<number>, | ||
}; | ||
|
||
(x ? x.a : []).map(n => { | ||
if (n !== '') { // number incompatible with string | ||
} | ||
}); |
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