1
respuesta

error no me funciona

[{ "resource": "/c:/Users/sasha/OneDrive/Escritorio/programacion/typescript/Parte1/typescript-fundamentos-ProyectoInicial/app/models/negociacion.ts", "owner": "typescript", "code": "2362", "severity": 8, "message": "La parte izquierda de una operación aritmética debe ser de tipo "any", "number", "bigint" o un tipo de enumeración.", "source": "ts", "startLineNumber": 23, "startColumn": 16, "endLineNumber": 23, "endColumn": 29 },{ "resource": "/c:/Users/sasha/OneDrive/Escritorio/programacion/typescript/Parte1/typescript-fundamentos-ProyectoInicial/app/models/negociacion.ts", "owner": "typescript", "code": "2363", "severity": 8, "message": "La parte derecha de una operación aritmética debe ser de tipo "any", "number", "bigint" o un tipo de enumeración.", "source": "ts", "startLineNumber": 23, "startColumn": 32, "endLineNumber": 23, "endColumn": 43 }]

export class Negociacion { private _fecha: Date; private _cantida: Number; private _valor: Number; constructor(fecha: Date, cantidad: Number, valor: Number){ this._fecha = fecha; this._cantida = cantidad; this._valor = valor; } get fecha(){ return this._fecha }

get cantidad() {
    return this._cantida
}

get valor() {
    return this._valor
}

get total(){
    return this._cantida * this._valor
}

} Ingrese aquí la descripción de esta imagen para ayudar con la accesibilidad

1 respuesta

No se si se les solicito realizar el código con el tipo Number, pero el error puede solucionarse utlizando el tipo primitivo, osea number, quedaría algo así:

export class Negociacion {
  private _fecha: Date;
  private _cantida: number;
  private _valor: number;

  constructor(fecha: Date, cantidad: number, valor: number) {
    this._fecha = fecha;
    this._valor = valor;
    this._cantida = cantidad;
  }

  getFecha() {
    return this._fecha;
  }

  getCantidad() {
    return this._cantida;
  }

  getValor() {
    return this._valor;
  }

  get total() {
    return this._cantida * this._valor;
  }
}