hapi-decorators
hapi-decorators copied to clipboard
how to use with typescript?
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.
What is the error(s) you are seeing?
@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"
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.