[FIXED] Getter is not present for class setter ***

Issue

I developed sample Dto as follows. But it generated some errors.

import { Shop } from "@post-pricing/library/lib/src/orm/typeorm/entity";
import { parse } from "@post-pricing/library/lib/src/utility/date"

export class ShopTransactionsDto {
    private event;
    private shopInfo:Shop;
    private transaction;

    constructor(){
        this.event = null;
        this.shopInfo = null;
        this.transaction = null;
    }

    set setEvent(event) {
        this.event = event
    }

    get getEvent() {
        return this.event
    }

    set setShopInfo(shopInfo:Shop){
        this.shopInfo = shopInfo
    }

    get getShopInfo() {
        return this.shopInfo
    }

    set setTransaction(transaction) {
        this.transaction = transaction
    }

}

One of errors is follows. I set getter in my class. what it the root cause of this?

  15:5  error  Getter is not present for class setter 'setEvent'        accessor-pairs
  23:5  error  Getter is not present for class setter 'setShopInfo'     accessor-pairs
  31:5  error  Getter is not present for class setter 'setTransaction'

If someone has opinion,please let me know.
Thanks

Solution

accessor-pairs linter you use requires a getter and a setter to have the same name, eg:

    set event(event) {
        this._event = event // note the field was renamed
    }

    get event() {
        return this._event
    }

References:

Answered By – zerkms

Answer Checked By – Cary Denson (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published