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?

2
  • #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. So in your case, you could cast it to something, such as: new Modeler({container: '#modeler'}) as InstanceType<typeof Modeler> Commented Nov 3, 2020 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. Commented Nov 4, 2020 at 15:46

1 Answer 1

1

Finally got it working:

data() {
    return {
        modeler: markRaw({} as InstanceType<typeof Modeler>)
    }
}
...
mounted() {
    this.modeler = markRaw(new Modeler({container: '#modeler'}))
}
Sign up to request clarification or add additional context in comments.

Comments

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.