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

implements keyword #2376

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

implements keyword #2376

vaukalak opened this issue Sep 1, 2016 · 6 comments

Comments

@vaukalak
Copy link

@vaukalak 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
Copy link

@AlexJozwicki AlexJozwicki commented Sep 1, 2016

Would be quite great indeed to have this

@vkurchatkin
Copy link
Contributor

@vkurchatkin vkurchatkin commented Sep 1, 2016

Here is a workaround:

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

@vaukalak 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
Copy link

@gcanti gcanti commented Sep 2, 2016

Also

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

@alexeygolev alexeygolev commented Sep 5, 2016

implements would be nice though.

@jeffmo
Copy link
Member

@jeffmo 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants