-
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] Prevent method-unbinding errors when there is a mixed/any hint
Summary: method-unbinding prevents errors by disallowing you from unbinding a method from the `this` required to call it. However, this behavior is incompatible with things like jest.expect: ``` // ERROR, cannot unbind method from foo expect(foo.method).toBeCalled... ``` We can take advantage of LTI to make this experience significantly better. In this diff, when we see a hint of `mixed` (which cannot be called) or `any` (which indicates an explicit opt-out of safety) we allow a method to be unbound without any errors. Reviewed By: mvitousek Differential Revision: D54157530 fbshipit-source-id: 50f32fff815ff6582ed1828a4db5cd91eae21943
- Loading branch information
1 parent
7cf8cbf
commit ef4c97f
Showing
9 changed files
with
121 additions
and
41 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
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 @@ | ||
declare function expectMixed(x: mixed): void; | ||
declare function expectAny(x: any): void; | ||
|
||
class Foo { | ||
method(): number { return 3; } | ||
} | ||
|
||
const foo = new Foo(); | ||
expectMixed(foo.method); // OK | ||
expectAny(foo.method); // OK |