"Maximum call stack size exceeded" error when instantiating object

Asked

Viewed 258 times

0

I have the following classes in an Ionic 2 app

export class JobIteractionsModel {

    public _idJob: number;
    get idJob() { return this._idJob }
    set idJob(idJob: number) { this._idJob = idJob }

    public _dataHoraInicio: Date;
    get dataHoraInicio() { return this._dataHoraInicio }
    set dataHoraInicio(dataHoraInicio: Date) { this._dataHoraInicio = dataHoraInicio }

    public _dataHoraFim: Date;
    get dataHoraFim() { return this._dataHoraFim }
    set dataHoraFim(dataHoraFim: Date) { this._dataHoraFim = dataHoraFim }

    public _valorTotal: number;
    get valorTotal() { return this._valorTotal }
    set valorTotal(valorTotal: number) { this._valorTotal = valorTotal }
}



import { JobIteractionsModel } from './JobIteractionsModel';
export class JobModel {

    public _id: number;
    get id() { return this._id }
    set id(id: number) { this._id = id }

    public _cliente: string;
    get cliente() { return this._cliente }
    set cliente(cliente: string) { this._cliente = cliente }

    public _telefone: string;
    get telefone() { return this._telefone }
    set telefone(telefone: string) { this._telefone = telefone }

    public _email: string;
    get email() { return this._email }
    set email(email: string) { this._email = email }

    public _descricao: string;
    get descricao() { return this._descricao }
    set descricao(descricao: string) { this._descricao = descricao }

    public _interacoes: JobIteractionsModel[];
    get interacoes() { return this.interacoes }
    set interacoes(interacoes: JobIteractionsModel[]) { this._interacoes = interacoes }

    public _adicionaInteracao(interacao: JobIteractionsModel) {
        this.interacoes.push(interacao);
    }

    public _deletaInteracao(index) {
        this.interacoes.splice(index, 1);
    }

    public _subtotal: number;
    get subtotal() { return this.subtotal }
    set subtotal(subtotal: number) { this._subtotal = subtotal }

    public _desconto: number;
    get desconto() { return this.desconto }
    set desconto(desconto: number) { this._desconto = desconto }

    public _total: number;
    get total() { return this.total }
    set total(total: number) { this._total = total }

}

When I create a new instance of the class Jobmodel and check on the Chrome element inspecter, the property interactions, "Maximum call stack size exceeded" error is being displayed.

Same error appears when trying to use method _additionInteration of a class instance Jobmodel.

Erro exibido ao depurar no Chrome

Erro exibido no console

I don’t understand why yet, but when I invoke the method, _additionInteration() inserir a descrição da imagem aqui

Enter the method inserir a descrição da imagem aqui

And then the execution goes to this line, and it runs recursively until the error. inserir a descrição da imagem aqui

Any help will be most welcome.

  • Chrome console shows no error?

  • Shows what is released on the console

  • Maybe relevant: https://github.com/Microsoft/TypeScript/issues/12735

  • I edited the question including a console print.

  • @merchant, Giovane included the console print and new prints to better detail the problem. Thank you.

1 answer

1

Thank you all, I managed to settle here.

It was an error in the name of the property _interactions, in class Jobmodel. Basically I changed from:

public _interacoes: JobIteractionsModel[];
get interacoes() { return this.interacoes } //<- Esta linha estava causando a recursividade
set interacoes(int: JobIteractionsModel[]) { this._interacoes = int }

To:

public _interacoes: JobIteractionsModel[];
get interacoes() { return this._interacoes }
set interacoes(int: JobIteractionsModel[]) { this._interacoes = int }

And then I changed the array statement _interactions initiating.

public _interacoes: JobIteractionsModel[] = [];
get interacoes() { return this._interacoes }
set interacoes(int: JobIteractionsModel[]) { this._interacoes = int }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.