Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add support for [[call]] internal slot properties
Summary:
In the previous commit, I deprecated the use of `$call` properties. Some uses
can be subsumed by callable property syntax, but not all. The existing callable
property syntax can only be used with function types, for example. This syntax
can be used with any type.
Unlike deprecated `$call` syntax, the `[[call]]` syntax will define an
overloaded call signature if combined with callable properties or other
`[[call]]` properties.
This syntax can also be used to resolve the ambiguity static callable
properties in declared classes. `declare class C { static (): void }`
currently defines a callable class, but it could also be a class with an
instance method named `static`. This diff preserves the existing behavior.
Reviewed By: panagosg7
Differential Revision: D8042915
fbshipit-source-id: 70111db89295e593999ed5999a90c178aeeb168a- Loading branch information
1 parent
df8ee96
commit 954a727
Showing
3 changed files
with
194 additions
and
15 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| type O = { | ||
| [[call]](): void; | ||
| } | ||
|
|
||
| ({}: O); // err: no callable property | ||
| (function() { return 0 }: O); // err: number ~> void | ||
| (function() {}: O); // ok | ||
|
|
||
| interface I { | ||
| [[call]](): void; | ||
| } | ||
|
|
||
| ({}: I); // err: no callable property | ||
| (function() { return 0 }: I); // err: number ~> void | ||
| (function() {}: I); // ok | ||
|
|
||
| declare class C1 { | ||
| static [[call]](): void; | ||
| } | ||
| (C1(): empty); // error: void ~> empty | ||
|
|
||
| declare var mixed_callable: { [[call]]: mixed }; | ||
| mixed_callable(); | ||
|
|
||
| declare var annot_callable: { [[call]]: Fn } | ||
| type Fn = string => number; | ||
| (annot_callable("foo"): number); // OK | ||
| annot_callable(0); // error: number ~> string | ||
| (annot_callable("foo"): empty); // error: number ~> empty |