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

how to use with typescript? #16

Open
iSword007 opened this issue Jul 30, 2018 · 3 comments
Open

how to use with typescript? #16

iSword007 opened this issue Jul 30, 2018 · 3 comments

Comments

@iSword007
Copy link

how to use with typescript?can you give me a example?

@controller('/service')
class ServiceController implements Controller {
  baseUrl!: string;
  routes!: () => ServerRoute[];

  @route('get', '/')
  async re (request, h) {
    const service: ServiceModel = request.getModel('service');
    return await service.findById();
  }
}

export default ServiceController;

I have to code so that VSCode haven't error.

@knownasilya
Copy link
Owner

What is the error(s) you are seeing?

@adancarrasco
Copy link

@iSword007 - Did you manage to make it work?

@knownasilya - The error I see is the following:

Argument of type 'typeof TestController' is not assignable to parameter of type 'ControllerStatic'.
Type 'TestController' is missing the following properties from type 'Controller': baseUrl, routests(2345)

My code:

@controller('/test')
class TestController {
  constructor() {}
}

I'm using:
TypeScript: Version 3.9.7
Node: v12.18.3
hapi: "^18.4.0"
@types/hapi-decorators: "^0.4.11"
hapi-decorators: "^2.0.0"

@Onimishra
Copy link

Onimishra commented Jun 23, 2021

For those still wandering about this issue, it can be solved by having

interface TestController extends Controller { }

in the same file as the class. The decorator will ensure that the methods are actually there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants