Tips for sending TypeScript objects to Vue components

Currently, I am working with the Vue 2 composition API plugin along with typescript version 3.9.7.

In my project, I have a simple type defined as Usp which I want to pass as a prop to a component named UspSection.

The structure of the USP type is outlined below:

export interface Image {
  sourceUrl: string;
}

export interface ImageWithText {
  text: string;
  image: Image;
}

export interface Usp {
  title: string;
  content: string;
  order: number;
  reverse: boolean;
  carousel: ImageWithText[];
}

Here is the script section from the UspSection component:

<script lang="ts">
import Vue, { PropType } from "vue";
import { defineComponent, ref } from "@vue/composition-api";
import { Usp } from "../types/usp";

export default defineComponent({
  props: {
    usp: {
      type: Object as PropType<Usp>,
      required: true,
    },
  },

  setup(props) {
    const slideNo = ref(0);

    console.log(props.usp);

    return {
      slideNo,
    };
  },
});
</script>

However, when I run the project, Vue throws an error even though the project still functions correctly. The specific error displayed in the console reads as follows:

ERROR in C:/Users/Oliver/Workspace/duet3d/client/src/components/UspSection.vue(34,16):
...
<!-- The rest of the error message remains the same -->

Any insights into what might be causing this issue would be greatly appreciated.

Thank you!

Answer №1

Try utilizing PropType from '@vue/composition-api' rather than using 'vue' directly

If this applies to your situation, modify the import statement like so:

import { defineComponent, PropType, ref } from '@vue/composition-api';

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

Using Next.js, it is not possible to use absolute imports within SASS

Having trouble utilizing @/ imports within my scss files. The variables I need are stored in src/styles/_variables.scss Here is my tsconfig.json: { "compilerOptions": { "lib": ["dom", "dom.iterable", "esnext"], "baseUrl": ".", "allowJs": tr ...

Angular's NgShoppingCart is designed in such a way that items stored in the localStorage are automatically cleared out

I am currently working on an Angular project using version 8.0.0. To integrate a shopping cart feature into my Angular project, I decided to incorporate the NgShoppingCart library by following the instructions provided here. After adding the library in m ...

What is the method for implementing conditions within a button element in Vue.js 2?

Here is an example of my component code: ... <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> ... <script> import { mapGetters } from 'vuex' export default{ ...

Utilizing Express-WS app and TypeScript to manage sessions

I am currently working on setting up a node server using Typescript with the help of express and express-ws. My goal is to include Sessions in my application, so I have implemented express-session. Below you can find some pseudo code: import * as session ...

Switching elements in an array using Vue.js

Within my vue.js web application, I am attempting to switch the positions of two rows in a forum. Below is the code snippet I am using: export default { data() { return { forums: [] } }, met ...

React: Unable to locate an index signature with a parameter of type 'string' on type N

While working with a React component, I encountered an issue when trying to access a property from my component state using a key. My editor showed the following warning: Element implicitly has an 'any' type because expression of type 'str ...

Is it possible to incorporate click methods within vuex?

Recently, I've been delving into learning Vue and Vuex. One thing I noticed is that I have repetitive code in different components. To streamline this, I decided to utilize Vuex to store my data in index.js, which has proven to be quite beneficial. No ...

Explore Syncfusion Vue component for dynamic element manipulation and customization

While working with syncfusion Vue controls, I've noticed that the documentation provides examples that access controls using $refs in some cases, while in others they use raw JavaScript like getelementbyid. At times, trying to use $refs results in pro ...

The test.ts file does not contain any type definitions

While I am able to successfully utilize my types in .ts files, I am facing difficulties in understanding why it's failing in .test.ts files, even though both files are located in the same folder. Check out the code in the .ts file below: https://i.s ...

The click event does not trigger in a Vue.js component when using v-on

I am utilizing VueJs to develop the following component. var ComponentTest = { props: ['list', 'symbole'], data: function(){ return { regexSymbole: new RegExp(this.symbole), } }, template: ` ...

Retrieve TypeScript object after successful login with Firebase

I'm struggling with the code snippet below: login = (email: string, senha: string): { nome: string, genero: string, foto: string;} => { this.fireAuth.signInWithEmailAndPassword(email, senha).then(res => { firebase.database().ref(&ap ...

Is there a way to dynamically change an icon based on certain conditions using typescript?

I am struggling with displaying icons in my TypeScript code using Material Icons. I need to dynamically change the icon based on a condition, for example if the power is false I want to display 'power_off', but if it's true then I want to di ...

HTMLElement addition assignment failing due to whitespace issues

My current challenge involves adding letters to a HTMLElement one by one, but I'm noticing that whitespace disappears in the process. Here's an example: let s = "f o o b a r"; let e = document.createElement('span'); for (let i ...

What is causing the lack of updated data on the components when navigating to a different page? (Vue.JS 2)

I am working with 2 components The first component looks like this : http://pastebin.com/M8Q3au0B Due to the long code, I have used pastebin for it The first component calls the second component The second component is as follows: <template> ...

Angular: Connecting template data to different visual presentations

Looking for a solution to display data and map values to another presentation without needing complex ngIf statements or creating multiple components. Check out this sample: https://stackblitz.com/edit/angular-9l1vff The 'vals' variable contain ...

Custom HTML binding in expanding rows of Angular 2 DataTables

I am currently working on implementing a data table feature that allows for an extended child row to be displayed when clicking the + icon. This row will show additional data along with some buttons that are bound via AJAX before transitioning to Angular 2 ...

Best practices for handling HTTP requests in Angular 5

I'm currently developing multiple applications using Angular 5. My aim is to adhere to all the dos and don'ts of Angular. However, I'm facing some confusion regarding a few things. 1) What is the difference between this... this._http.g ...

Guide to tallying the occurrences of a specific key within an object array and attaching the count to each key's current value

Is there a way to determine the number of occurrences of the 'value' key within an object that is part of an array, and then add the count to each value if applicable? In this case, 'a' represents the original data var a = [ { id: ...

DataGrid parameters in Material UI are only considering the final value in the table

I am working with a Data Grid table containing user information, and I want to include a sub-menu of options in the last column that opens up a modal for each user. However, I am facing an issue where only the data from the final row in the table is being ...

Using NextJs <Script> is only effective after a page has been reloaded

Currently delving into the world of NextJS and encountering an issue with integrating a third-party ebay script onto one of my route pages. The script only seems to appear sporadically upon reloading the page. However, when navigating to the store page via ...