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

implements keyword #2376

Closed
vaukalak opened this Issue Sep 1, 2016 · 6 comments

Comments

Projects
None yet
6 participants
@vaukalak
Copy link

vaukalak commented Sep 1, 2016

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;
  }
}
@AlexJozwicki

This comment has been minimized.

Copy link

AlexJozwicki commented Sep 1, 2016

Would be quite great indeed to have this

@vkurchatkin

This comment has been minimized.

Copy link
Contributor

vkurchatkin commented Sep 1, 2016

Here is a workaround:

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

This comment has been minimized.

Copy link
Author

vaukalak commented Sep 1, 2016

@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.

@gcanti

This comment has been minimized.

Copy link

gcanti commented Sep 2, 2016

Also

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

This comment has been minimized.

Copy link

alexeygolev commented Sep 5, 2016

implements would be nice though.

@jeffmo

This comment has been minimized.

Copy link
Member

jeffmo commented Sep 9, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment