0

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;
        |                     ^
4
  • why not selectedOrder: ''? Commented Jan 8, 2020 at 12:44
  • then I get error: property 'processInstanceId' does not exist on type 'string'. Commented Jan 8, 2020 at 12:47
  • maybe this.selectedOrder.processInstanceId.toString() Commented Jan 8, 2020 at 12:52
  • no, still Property 'processInstanceId' does not exist on type 'string'. Commented Jan 8, 2020 at 12:53

1 Answer 1

2

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,
      };
    },
    ...
})

 

Sign up to request clarification or add additional context in comments.

2 Comments

I rather did : ` selectedOrder: { processInstanceId: '', declineMessage: '' },` is that bad? its working this way too
if you will do it like so then is not neccesary TS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.