farahm
farahm

Reputation: 1326

Typescript vue Object is possibly 'null'

I have already checked the questions of the past, but I could not find a solution that worked for me.

I am using Vue Typescript:

export default Vue.extend({

    data() {
      return {
        ...
        selectedOrder: null,
      };
    },



approveOrder() {
        if(this.selectedOrder !== undefined && this.selectedOrder!==null && this.selectedOrder !== '') {
          let uri = 'http://localhost:8081/v1/order/approve/';

          uri = uri + this.selectedOrder.processInstanceId + '?approverId=' + this.getUser;

Error I get is:

164:21 Object is possibly 'null'.
    162 |           let uri = 'http://localhost:8081/v1/order/approve/';
    163 |
  > 164 |           uri = uri + this.selectedOrder.processInstanceId + '?approverId=' + this.getUser;
        |                     ^

Upvotes: 0

Views: 2728

Answers (1)

Christian Carrillo
Christian Carrillo

Reputation: 2761

u are not using using the advantages of typescript, i guess you should set any type to your selectedOrder object, you could try as bellow:

// selectedOrder.interface.ts
interface selectedOrder {
    processInstanceId: Number;
}

 in your vue component you should to import your interface file, then:

// component.vue
export default Vue.extend({
    data() {
      return {
        ...
        selectedOrder: { processInstanceId: 0 } as selectedOrder,
      };
    },
    ...
})

 

Upvotes: 2

Related Questions