Flow: implements keyword

Created on 1 Sep 2016  路  6Comments  路  Source: facebook/flow

So there a lot of issues where is feature is mentioned, but theres no one specific for it.
The desired result would be to achieve following syntax:

interface A {
  foo() : number;
}

class AImpl implements A {
   foo() : number {
    return 1;
  }
}
feature request

Most helpful comment

implements would be nice though.

All 6 comments

Would be quite great indeed to have this

Here is a workaround:

class AImpl {
  constructor() {
    (this: A);
  }
   foo() : number {
    return 1;
  }
}

@vkurchatkin wow, I think that it's not only a workaround, but we could roll with that. Maybe the syntax is not so perfect, but that seems to cover all use cases of implements. You can also implement more than one interface:

class AImpl {
  constructor() {
    (this: A & B);
  }
  ....
}

I'll send a PR for documenting this on the week.

Also

class AImpl {
  constructor(): A {
    return this
  }
  foo() : number {
    return 1
  }
}

implements would be nice though.

We'd like to get to this, but it's not high priority at the moment because @vkurchatkin's workaround works fairly well.

Was this page helpful?
0 / 5 - 0 ratings