TypeError: Cannot read property 'get' of undefined
See original GitHub issueWhen inject a service in controller using the decorator
How to reproduce:
import { Controller, GET, Inject } from "fastify-decorators";
import { AnyService } from "../services";
@Controller("/status")
export default class HelloController {
@Inject(AnyService)
private anyService: AnyService;
@GET()
async handler(): Promise<{ hello: string }> {
try {
console.log(this.anyService);
} catch (e) {
console.log(e);
}
return { hello: "world" };
}
}
TypeError: Cannot read property 'get' of undefined
at StatusController.get [as cache] (/home/ferco/workspace/http-service-template/lib/decorators/inject.ts:26:42)
at StatusController.<anonymous> (/home/ferco/workspace/http-service-template/src/controllers/status.controller.ts:35:24)
at Generator.next (<anonymous>)
at /home/ferco/workspace/http-service-template/src/controllers/status.controller.ts:17:71
at new Promise (<anonymous>)
at __awaiter (/home/ferco/workspace/http-service-template/src/controllers/status.controller.ts:13:12)
at StatusController.handler (/home/ferco/workspace/http-service-template/src/controllers/status.controller.ts:41:16)
at Object.<anonymous> (/home/ferco/workspace/http-service-template/lib/decorators/strategies/controller-type.ts:52:61)
at preHandlerCallback (/home/ferco/workspace/http-service-template/node_modules/fastify/lib/handleRequest.js:120:28)
at preValidationCallback (/home/ferco/workspace/http-service-template/node_modules/fastify/lib/handleRequest.js:103:5)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Cannot Read Property of Undefined in JavaScript - Rollbar
What Causes TypeError: Cannot Read Property of Undefined. Undefined means that a variable has been declared but has not been assigned a value....
Read more >TypeError: Cannot read property 'get' of undefined on AngularJS
You are getting this error because $http is undefined in your factory. You can fix it by passing it to the factory like...
Read more >Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >TypeError: Cannot read property 'get' of undefined at Object ...
I can't provide a link to a playground as this issue seems to be tied to the structure of the repository and dependencies....
Read more >TypeError: Cannot read property 'get' of undefined - Code Help
Code : let prefix = client.guildSettings.get(message.guild.id,"prefix") Error : TypeError: Cannot read property 'get' of undefined Can ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Released as v3.1.1
Thanks for clarification! I will take a look what I can do on it