-
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.
[PR] Fix for class method default parameters that use
this
Summary: Example of bug - https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoVBjGBDAzrsAQTAG9UwxyxsAuMXAFwCcBLAOwHMqqAjACgxgAvGAYALFrgB02AJSkqFKgF9uyoA Fixes #3353 Fixes #1234 Closes #3334 Reviewed By: samwgoldman Differential Revision: D4523083 Pulled By: jeffmo fbshipit-source-id: 6e8be65711263182d8eef568ae34a46d77b399a3
- Loading branch information
1 parent
3e4d589
commit d3887c2
Showing
4 changed files
with
38 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[options] | ||
no_flowlib=false |
8 changes: 8 additions & 0 deletions
8
tests/class_method_default_parameters/class_method_default_parameters.exp
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,8 @@ | ||
class_method_default_parameters.js:17 | ||
17: h(i: number = this.b) { // error | ||
^^^^^^ string. This type is incompatible with | ||
17: h(i: number = this.b) { // error | ||
^^^^^^ number | ||
|
||
|
||
Found 1 error |
21 changes: 21 additions & 0 deletions
21
tests/class_method_default_parameters/class_method_default_parameters.js
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,21 @@ | ||
class A { | ||
|
||
b: string; | ||
|
||
c(d = this.b) { // ok - can use `this` in function default parameter values | ||
|
||
} | ||
|
||
e() { | ||
return this.b; | ||
} | ||
|
||
f(g = this.e()) { // ok - can use `this` in function default parameter values | ||
|
||
} | ||
|
||
h(i: number = this.b) { // error | ||
|
||
} | ||
|
||
} |