Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for chainable APIs aka This type #399

Closed
claudio-silva opened this issue Apr 19, 2015 · 8 comments
Closed

Support for chainable APIs aka This type #399

claudio-silva opened this issue Apr 19, 2015 · 8 comments

Comments

@claudio-silva
Copy link

This code:

/* @flow */

class A {
  x():A {
    return this;
  }
}

class B extends A {
  y():B {
    return this;
  }
}

var w = new B();

w.x().y();

Gives this error:

hello.js:17:1,9: call of method y
Property not found in
  hello.js:3:7,7: A

How can I express the return type of A.x() to be the same type as the instance's type where x() is invoked on?
This is very important for any javascript library that implements a chainable API where elements on the chain may subclass a base class and inherit chainable methods.

@samwgoldman
Copy link
Member

I don't have a solution here, but this sounds like Objective-C's instancetype to me.

@claudio-silva if you were writing in a different statically typed language, how would you write this?

@claudio-silva
Copy link
Author

Hi @samwgoldman, I don't know Objective-C, but doing a quick search it seems that instancetype is something quite similar to this.
As for other examples of this feature on other languages:
The Typescript team is investigating this issue and brainstorming solutions for it, as you can see in this issue on GitHub.
Scala has this.type. See this article.
In PHPDocumentor, you can use the $this keyword as a function return type. See this reference. It is a very useful feature that allows you to get correct autocompletion on IDEs (ex: PHPStorm).
PHPDocumentor also defines self and static which have other meanings, but that may potentially also be useful for use with Javascript.

@avikchaudhuri avikchaudhuri changed the title Support for chainable APIs Support for chainable APIs aka This type Jun 19, 2015
@claudio-silva
Copy link
Author

@samwgoldman I see you have closed this, but no reason was presented. Is this issue solved?

@samwgoldman
Copy link
Member

@claudio-silva Sorry about that. I closed this because we released support for this types in 0.20.0!

@claudio-silva
Copy link
Author

Great! Thanks!
But I can't find anything about it on the Flow documentation site!
Also, on the site's Blog section (a changelog), you've skipped version 0.20 and went from 0.19 to 0.21, so there is no mention of what's new on version 0.20!!!
Where can I find more info about these new features?

@samwgoldman
Copy link
Member

Yeah, thanks for calling us out on that. We're actually working on a big docs push, but it's definitely embarrassing that we added a feature and didn't document it. We're putting a lot of effort into the revamp, and are working to ensure that the docs stay updated as we build new features.

We've also not been great at announcing new versions on the blog, but the Changelog.md file in this repo does always get updated and has a sparse breakdown of the changes we've made and features added.

@claudio-silva
Copy link
Author

Thank you for your kind response.
I'll stay tuned for documentation updates.

@pronebird
Copy link

Is there any documentation on this type?

facebook-github-bot referenced this issue Oct 24, 2019
Summary:
Bumps [rubyzip](https://github.com/rubyzip/rubyzip) from 1.2.2 to 1.3.0.
<details>
<summary>Release notes</summary>

*Sourced from [rubyzip's releases](https://github.com/rubyzip/rubyzip/releases).*

> ## v1.3.0
> Security
>
> - Add `validate_entry_sizes` option so that callers can trust an entry's reported size when using `extract` [https://github.com/facebook/flow/issues/403](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/403)
>    - This option defaults to `false` for backward compatibility in this release, but you are strongly encouraged to set it to `true`. It will default to `true` in rubyzip 2.0.
>
> New Feature
>
> - Add `add_stored` method to simplify adding entries without compression [https://github.com/facebook/flow/issues/366](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/366)
>
> Tooling / Documentation
>
> - Add more gem metadata links [https://github.com/facebook/flow/issues/402](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/402)
>
> ## v1.2.4
> - Do not rewrite zip files opened with `open_buffer` that have not changed [https://github.com/facebook/flow/issues/360](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/360)
>
> Tooling / Documentation
>
> - Update `example_recursive.rb` in README [https://github.com/facebook/flow/issues/397](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/397)
> - Hold CI at `trusty` for now, automatically pick the latest ruby patch version, use rbx-4 and hold jruby at 9.1 [https://github.com/facebook/flow/issues/399](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/399)
>
> ## v1.2.3
> * Allow tilde in zip entry names [https://github.com/facebook/flow/issues/391](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/391) (fixes regression in 1.2.2 from [https://github.com/facebook/flow/issues/376](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/376))
> * Support frozen string literals in more files [https://github.com/facebook/flow/issues/390](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/390)
> * Require `pathname` explicitly [https://github.com/facebook/flow/issues/388](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/388) (fixes regression in 1.2.2 from [https://github.com/facebook/flow/issues/376](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/376))
>
> Tooling / Documentation:
>
> * CI updates [https://github.com/facebook/flow/issues/392](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/392), [https://github.com/facebook/flow/issues/394](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/394)
>    * Bump supported ruby versions and add 2.6
>    * JRuby failures are no longer ignored (reverts [https://github.com/facebook/flow/issues/375](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/375) / part of [https://github.com/facebook/flow/issues/371](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/371))
> * Add changelog entry that was missing for last release [https://github.com/facebook/flow/issues/387](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/387)
> * Comment cleanup [https://github.com/facebook/flow/issues/385](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/385)
>
> Since the GitHub release information for 1.2.2 is missing, I will also include it here:
>
> ### 1.2.2
>
> NB: This release drops support for extracting symlinks, because there was no clear way to support this securely. See https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/376#issue-210954555 for details.
>
> * Fix CVE-2018-1000544 [https://github.com/facebook/flow/issues/376](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/376) / [https://github.com/facebook/flow/issues/371](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/371)
> * Fix NoMethodError: undefined method `glob' [https://github.com/facebook/flow/issues/363](https://github.com/rubyzip/rubyzip/pull/363)
> * Fix handling of stored files (i.e. files not using compression) with general purpose bit 3 set [https://github.com/facebook/flow/issues/358](https://github.com/rubyzip/rubyzip/pull/358)
> * Fix `close` on StringIO-backed zip file [https://github.com/facebook/flow/issues/353](https://github.com/rubyzip/rubyzip/pull/353)
> * Add `Zip.force_entry_names_encoding` option [https://github.com/facebook/flow/issues/340](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/340)
> * Update rubocop, apply auto-fixes, and fix regressions caused by said auto-fixes [https://github.com/facebook/flow/issues/332](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/332), [https://github.com/facebook/flow/issues/355](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/355)
> * Save temporary files to temporary directory (rather than current directory) [https://github.com/facebook/flow/issues/325](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/325)
>
> Tooling / Documentation:
></tr></table> ... (truncated)
</details>
<details>
<summary>Changelog</summary>

*Sourced from [rubyzip's changelog](https://github.com/rubyzip/rubyzip/blob/master/Changelog.md).*

> # 1.3.0 (2019-09-25)
>
> Security
>
> - Add `validate_entry_sizes` option so that callers can trust an entry's reported size when using `extract` [https://github.com/facebook/flow/issues/403](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/403)
>    - This option defaults to `false` for backward compatibility in this release, but you are strongly encouraged to set it to `true`. It will default to `true` in rubyzip 2.0.
>
> New Feature
>
> - Add `add_stored` method to simplify adding entries without compression [https://github.com/facebook/flow/issues/366](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/366)
>
> Tooling / Documentation
>
> - Add more gem metadata links [https://github.com/facebook/flow/issues/402](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/402)
>
> # 1.2.4 (2019-09-06)
>
> - Do not rewrite zip files opened with `open_buffer` that have not changed [https://github.com/facebook/flow/issues/360](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/360)
>
> Tooling / Documentation
>
> - Update `example_recursive.rb` in README [https://github.com/facebook/flow/issues/397](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/397)
> - Hold CI at `trusty` for now, automatically pick the latest ruby patch version, use rbx-4 and hold jruby at 9.1 [https://github.com/facebook/flow/issues/399](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/399)
>
> # 1.2.3
>
> - Allow tilde in zip entry names [https://github.com/facebook/flow/issues/391](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/391) (fixes regression in 1.2.2 from [https://github.com/facebook/flow/issues/376](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/376))
> - Support frozen string literals in more files [https://github.com/facebook/flow/issues/390](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/390)
> - Require `pathname` explicitly [https://github.com/facebook/flow/issues/388](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/388) (fixes regression in 1.2.2 from [https://github.com/facebook/flow/issues/376](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/376))
>
> Tooling / Documentation:
>
> - CI updates [https://github.com/facebook/flow/issues/392](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/392), [https://github.com/facebook/flow/issues/394](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/394)
>   - Bump supported ruby versions and add 2.6
>   - JRuby failures are no longer ignored (reverts [https://github.com/facebook/flow/issues/375](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/375) / part of [https://github.com/facebook/flow/issues/371](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/371))
> - Add changelog entry that was missing for last release [https://github.com/facebook/flow/issues/387](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/387)
> - Comment cleanup [https://github.com/facebook/flow/issues/385](https://github-redirect.dependabot.com/rubyzip/rubyzip/pull/385)
</details>
<details>
<summary>Commits</summary>

- [`e79d9ea`](rubyzip/rubyzip@e79d9ea) Merge pull request [https://github.com/facebook/flow/issues/407](https://github-redirect.dependabot.com/rubyzip/rubyzip/issues/407) from rubyzip/v1-3-0
- [`7c65e1e`](rubyzip/rubyzip@7c65e1e) Bump version to 1.3.0
- [`d65fe7b`](rubyzip/rubyzip@d65fe7b) Merge pull request [https://github.com/facebook/flow/issues/403](https://github-redirect.dependabot.com/rubyzip/rubyzip/issues/403) from rubyzip/check-size
- [`97cb6ae`](rubyzip/rubyzip@97cb6ae) Warn when an entry size is invalid
- [`7849f73`](rubyzip/rubyzip@7849f73) Default validate_entry_sizes to false for 1.3 release
- [`4167f0c`](rubyzip/rubyzip@4167f0c) Validate entry sizes when extracting
- [`94b7fa2`](rubyzip/rubyzip@94b7fa2) [ci skip] Update changelog
- [`93505ca`](rubyzip/rubyzip@93505ca) Check expected entry size in add_stored test
- [`6619bf3`](rubyzip/rubyzip@6619bf3) Merge pull request [https://github.com/facebook/flow/issues/366](https://github-redirect.dependabot.com/rubyzip/rubyzip/issues/366) from hainesr/add-stored
- [`ecb2776`](rubyzip/rubyzip@ecb2776) Zip::File.add_stored() to add uncompressed files.
- Additional commits viewable in [compare view](rubyzip/rubyzip@v1.2.2...v1.3.0)
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=rubyzip&package-manager=bundler&previous-version=1.2.2&new-version=1.3.0)](https://help.github.com/articles/configuring-automated-security-fixes)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

 ---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `dependabot rebase` will rebase this PR
- `dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `dependabot merge` will merge this PR after your CI passes on it
- `dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `dependabot cancel merge` will cancel a previously requested merge and block automerging
- `dependabot reopen` will reopen this PR if it is closed
- `dependabot ignore this [patch|minor|major] version` will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
- `dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/facebook/flow/network/alerts).

</details>
Pull Request resolved: #8147

Differential Revision: D18120615

Pulled By: nmote

fbshipit-source-id: 8bb7feb00ca2f10db52fbf16dc1939dad3557856
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants