Skip to content

Support for chainable APIs aka This type #399

Closed
@claudio-silva

Description

@claudio-silva

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions