TransWikia.com

Specify type of data value in Vue (typescript)

Stack Overflow Asked by Berco Beute on February 6, 2021

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?

One Answer

Finally got it working:

data() {
    return {
        modeler: markRaw({} as InstanceType<typeof Modeler>)
    }
}
...
mounted() {
    this.modeler = markRaw(new Modeler({container: '#modeler'}))
}

Answered by Berco Beute on February 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP