Please indicate the data type in Vue using Typescript

I'm currently struggling with Vue (3) + Typescript while attempting to specify a data property with a specific type. I have created a .d.ts file, but unfortunately, it hasn't helped. This is what I'm trying:

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

However, when I run this code, I encounter the following error message:

'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]')

Interestingly, if I define the instance of Modeler within the methods, everything works as expected:

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

I've already declared the module in my bpmnjs.d.ts file:

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

Any insights into what mistake I might be making here?

Answer №1

Success! Everything is up and running smoothly now:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigate to the top of the page using Vue Router when moving to a new

Currently, in my Vue application, whenever I click on a <router-link>, it directs me to the new page but at the same scroll position as the previous one. This happens because the link only replaces the component. I am curious to know if there is a s ...

Angular routing is showing an undefined ID from the snapshot

When a user attempts to update a student, I pass in the student ID. The update successfully redirects to the updateStudent page and displays the student ID in the browser link. However, within my app component, it shows as undefined. Student View componen ...

Vue.js using the v-for directive with index

Just started using Vue.js and I have a question: I'm working with an array to create a table. When I double click on a table row, I want the program to execute a JavaScript function that will retrieve the selected item based on its index. <di ...

Issue with Webpack in vue.js project when incorporating sasssass causing errors

I am new to Vue.js and webpack, and I'm not sure if the issue lies with the packages or my own mistake. Steps to replicate the problem: Create a new Vue project using the webpack template ~ vue init webpack sass-test ? Project name sass-test ? Proj ...

Angular - delay execution until the variable has a value

When the ngOnInit() function is called, the first line of code retrieves a value from local storage which is then used to filter data from the database. Both actions happen simultaneously, resulting in an issue where I don't receive the expected resu ...

Unable to transfer an object into a component due to a subscribe restriction

I have encountered an issue: I am making a post request to save an object in the database. The request takes JSON input with the values of the object to be saved. After saving the object in the database, I need my servlet to return the saved object so that ...

Updating the id token in VueJs using Axios interceptor when it expires

I need to implement an axios interceptor that will add the idToken as an authorization header to every axios call, and also refresh the idToken if it has expired before making any call. My current code for this task is as follows: axios.interceptors.requ ...

The event bus I'm using isn't functioning properly within the axios interceptor, yet it operates smoothly in all my Vue components

Currently, I am utilizing VueJs and mitt for the eventBus. The mitt is globally loaded and functioning correctly as shown below: main.js const emitter = mitt(); const app = createApp(App) app.config.globalProperties.emitter = emitter I am able to call t ...

I am finding it difficult to set up a new Vue project with all the necessary tools like vue-router, vuex, node-sass, babel, pwa, and eslint using the vue

Here are the details of my current setup: Operating System: Windows 10 @vue/cli Version: 3.12.1 Node Version: 16.2.0 I have selected the following features: vue-router, vuex, node-sass, babel, pwa, eslint When I attempt to run the command: vue create pro ...

How can we ensure that the load more button disappears at the appropriate moment in this Vue 3 application?

I have been developing a news application with Vue 3 and the News API. I am currently implementing a feature for loading more articles on the page. Initially, there are 24 articles displayed, and if there are more articles available than the current numbe ...

Tips for optimizing data loading in Angular by pre-loading data to prevent unnecessary Firebase reads

Issue: One specific part of my web application is responsible for fetching a large amount of data from Firebase Firestore whenever a user visits that section. This results in hundreds of thousands of unnecessary reads to my Firestore database. Inquiry: Ho ...

Exception occurs when arrow function is replaced with an anonymous function

Currently, I am experimenting with the Angular Heroes Tutorial using Typescript. The code snippet below is functioning correctly while testing out the services: getHeroes() { this.heroService.getHeroes().then(heroes => this.heroes = heroes); } H ...

Encountering a 404 error when using the NestJS GET function within the service and controller

I am facing an issue with creating simple GET logic. When I test it in Postman, I keep receiving a 404 error. books.service.ts contains the following basic logic: constructor( @InjectRepository(Books) private readonly booksRepo: Repository<Boo ...

assemble an individual Vue component

After creating a vue project with the command vue create myapp, I generated multiple components: src/components/MyFirst.vue src/components/MySecond.vue In addition, I made adjustments to my vue.config.js as follows: module.exports = { css: { extract ...

Tips for changing styles in a Vue Vuetify app based on language selection

Currently, I am working on a Vue.js application using Vuetify and Vue-i18n for internationalization. I have a specific font-family that I want to only be applied when the language is set to Arabic. In order to achieve this, I will need to switch styles bas ...

The name 'Queue' cannot be located in Typescript, error code ts(2304)

I'm currently trying to create a private variable of type InnerItem, but I keep encountering the following error: Error: Cannot find name 'Queue'.ts(2304) private savedItems: Queue<InnerItem> = new Queue<InnerItem>(20); Could ...

Accessing Angular's Observable Objects

I am currently in the process of learning Angular and trying to work with Observables. However, I am facing an issue where I cannot extract data from an Observable when it is in object form. public rowData$!: Observable<any[]>; UpdateGrid() { this ...

Client-side condition handling in Angular 2

How can I change the icon image on a block/unblock button based on the user's active status? For example, showing an unlock image when the user is active and vice versa. Image https://i.stack.imgur.com/aM0ff.png Html <link href="../../font-aw ...

Just can't seem to get my Rails 5.1 application with Vue and webpacker 3 to compile the CSS

I'm in the process of integrating Element UI into my Vue application. I've followed the steps outlined in the quick start tutorial and have set up my application.js file as follows: import Vue from 'vue' import ElementUI from 'el ...

The information in the map cannot be inferred by Typescript based on the generic key type

I encountered a TypeScript issue while refactoring an existing feature in my app. It seems that TypeScript is having trouble picking up the correct type when passing the generic type through nested functions. enum App { AppOne = 'app-one', A ...