首页 > 解决方案 > 无法读取未定义的属性“客户端”

问题描述

我正在尝试使用 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

标签: typescriptoop

解决方案


推荐阅读