typescript - 无法读取未定义的属性“客户端”
问题描述
我正在尝试使用 TypeScript 创建类。但是,当我执行该功能时。控制台表示Cannot read property 'client' of undefined
其均值this
未定义。但为什么?
代码:
import type { Request, Response } from "express";
import type { IRoute } from "../interfaces";
import type RaznarTicketClient from "../structures/RaznarClient";
export default class HomeRoute implements IRoute {
readonly name = "/";
constructor(public client: RaznarTicketClient) {}
public async exec(_: Request,res: Response) {
const tickets = await this.client.ticket.getTickets();
return res.json(tickets);
}
}
错误:TypeError: Cannot read property 'client' of undefined
解决方案
推荐阅读
- javascript - JavaScript-即使使用 slice() 洗牌后数组大小也会翻倍
- wpf - 路由事件处理程序拖放信息
- android - 尝试调用虚拟方法 'void android.support.v7.widget.CardView.setOnClickListener
- sql - 在每个 ID 中查找一些相同的值
- c# - 如何在后台运行控制台应用程序 [C#]
- c# - 实体框架核心错误?
- c# - C#读取字符并将其放置在特定位置
- javascript - 为什么 Socket.io 没有在我的 React Native 应用程序中连接
- node.js - 节点'readline'如何检测当前行是文件中的最后一行
- mysql - C3P0 明显死锁