0

I'm still lost in Vue (3) + Typescript trying to specify a data property of a certain type. I've added a .d.ts file but to no avail. I'm trying this:

import Modeler from 'bpmn-js/lib/Modeler'
...
data() {
    return {
        modeler: {} as InstanceType<typeof Modeler> // ?????
    },
}
...
methods: {
    do() {
        this.modeler.importXML(someXML)
    },
}
...

This results in:

'get' on proxy: property '$pkg' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '#<Object>' but got '[object Object]')

If I define the Modeler instance in methods things work just fine:

methods: {
    do() {
        const modeler = new Modeler({container: '#modeler'})
        modeler.importXML(someXML)
    },
}

I've declared the module as in bpmnjs.d.ts:

// bpmnjs.d.ts
declare module 'bpmn-js/lib/Modeler'

Any idea what I'm doing wrong here?

Berco Beute
  • 1,115
  • 15
  • 30
  • #1, `module` is a reserved contextual keyword, so you cannot use it as a type. In any case, you can cast your data properties. Since Typescript 1.6, the preferred method is using [as](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-1-6.html#new-tsx-file-extension-and-as-operator). So in your case, you could cast it to something, such as: `new Modeler({container: '#modeler'}) as InstanceType` – Ohgodwhy Nov 03 '20 at 23:39
  • Thanks. Your type declaration suggestion seems to work, but now I bump into the next issue. I've updated my question accordingly. – Berco Beute Nov 04 '20 at 15:46

1 Answers1

1

Finally got it working:

data() {
    return {
        modeler: markRaw({} as InstanceType<typeof Modeler>)
    }
}
...
mounted() {
    this.modeler = markRaw(new Modeler({container: '#modeler'}))
}
Berco Beute
  • 1,115
  • 15
  • 30