相关疑难解决方法(0)

为什么我无法访问打字稿类的构造函数中的抽象属性

abstract class Route {
    abstract readonly name?: string;
    protected abstract pattern: string;

    public constructor() {
        // Do something with `this.name` and `this.pattern`.
        
        console.log(this.pattern); // Typecheck error
    }
    
    abstract handle(): void;
}
Run Code Online (Sandbox Code Playgroud)

这会引发错误,因为this.pattern不会在构造函数中访问。为什么我无法访问它?

class abstract typescript

11
推荐指数
1
解决办法
5619
查看次数

标签 统计

abstract ×1

class ×1

typescript ×1