Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Implements basic parser support for specifying `this` type constraints in functions and function types. The syntax is similar to [`this` parameters in TypeScript](https://www.typescriptlang.org/docs/handbook/functions.html#this-parameters). ## Motivating use case NOTE: This is a hypothetical example. This diff does **not** implement any typechecking semantics. With this syntax, typing `Array.prototype.join` as ``` declare class $ReadOnlyArray<T> { join(this: $ArrayLike<string>, separator?: string): string; } ``` could make it an error to call `join` with a non-string element type, e.g. `[{}].join()`, thus guarding against the implicit string coercion inside the method. As a side benefit, it would allow `join` to be safely used on array-like objects that do not extend `Array`, which is explicitly allowed by [the spec](https://tc39.es/ecma262/#sec-array.prototype.join): > The `join` function is intentionally generic; it does not require that its `this` value be an Array object. Therefore, it can be transferred to other kinds of objects for use as a method. The spec uses similar "intentionally generic" language on many other built-in methods, providing other natural opportunities to use this feature in the core libdefs. Reviewed By: gkz Differential Revision: D22276547 fbshipit-source-id: b0cd0a921582e29bf29ec414b8c386cd411dda7b
- Loading branch information
1 parent
bc68f94
commit 8efdc8c
Showing
98 changed files
with
6,020 additions
and
154 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
Oops, something went wrong.