Error encountered in Vue 3 Typescript props: [Vue warning]: Prop validation failed for prop "organisation". It should be of type Null or Boolean, but an Object was passed instead

I am currently developing an application using Quasar/Vue. In my component, I am passing the "organisation" object to it.

<q-tab-panel name="roles">
   <OrganisationRolesTab :organisation="organisation"></OrganisationRolesTab>
</q-tab-panel>

Within OrganisationRolesTab.vue, I define the prop "organisation" using the defineProps generic notation:

<template>
  {{ organisation }}
</template>

<script setup lang="ts">
import { IOrganisation } from 'src/interfaces/IOrganisation'

defineProps<{ organisation: IOrganisation | false }>()
</script>

The structure of IOrganisation is as follows:

export interface IOrganisation {
  id?: string
  title: string
  shortTitle: string
  createdAt?: Date
  updatedAt?: Date
}

Upon implementation, a warning appeared in the console:

runtime-core.esm-bundler.js?f781:38 [Vue warn]: Invalid prop: type check failed for prop "organisation". Expected Null | Boolean, got Object  
  at <OrganisationRolesTab organisation= {id: '94de89d3-38f2-4410-bf86-74db781b18aa', createdAt: '2022-06-13T15:11:45.185Z', updatedAt: '2022-07-03T14:24:26.103Z', title: 'Test organisation', shortTitle: 'test'} > 
  at <QTabPanel name="roles" > 
  at <BaseTransition appear=false persisted=false mode=undefined  ... > 
  at <Transition name="q-transition--slide-right" > 
  at <QTabPanels modelValue="roles" onUpdate:modelValue=fn animated="" > 
  at <OrganisationEdit onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< Proxy {__v_skip: true} > > 
  at <RouterView> 
  at <QPageContainer class="q-ma-sm" > 
  at <QLayout view="lHh Lpr lFf" > 
  at <MainLayout onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< Proxy {$i18n: {…}, $t: ƒ, $rt: ƒ, …} > > 
  at <RouterView> 
  at <App>

How can I resolve this warning without compromising the typing?

Answer №1

The official documentation outlines the restrictions of using defineProps:

At present, the type declaration argument must adhere to specific criteria for accurate static analysis:

  • It should be a type literal
  • Or a reference to an interface or a type literal within the same file

Notably, complex types and importing types from other files are currently not supported. However, there is potential for adding support for type imports in upcoming versions.

To work around this limitation, one can utilize the equivalent options argument of defineProps:

<script setup lang="ts">
import type { PropType } from 'vue'

defineProps({
  organisation: Object as PropType<IOrganisation | boolean>
})
</script>

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 Vue.js causes an issue with Array.from(Object).forEach

When using vue.js 2 CLI, I typically define object data like this within the data() function: data(){ return{ user: { user_mail: '', user_password: '', user_confirm_password : '' ...

Increasing the value of a food topping element within a v-for list of toppings when clicking on the "+ add" button in Vue

I'm a newcomer to the world of JavaScript and Vue.js, currently working on a project to automate the ordering process for my pizza delivery pizzeria. On the website, I have a list of toppings that customers can choose from. They have the option to se ...

"Encountering issues with importing Splitpanes while using VueJs and TypeScript combination

My VueJS view was originally written in JavaScript using the component "splitpanes" from npm package. The code was functioning well with the following structure: <template> <div> <Splitpanes :dbl-click-splitter="false" :horizont ...

Complicated connections between TypeORM and MySQL

Currently leveraging TypeORM in tandem with MySQL, my database comprises of two main Entities, namely User and Project: @Entity() class User { @PrimaryGeneratedColumn('uuid') id: string; @Column({}) name: string; } @Entity() ...

Resolving TypeScript error: Property 'Error' does not exist on type 'Angular2 and Objects'

One of the models I am working with is called "opcionesautocomplete.model.ts" interface IOpcionesAutocomplete { opcionesStyle: OpcionStyle; pcionPropiedades: OpcionPropiedades; } export class OpcionesAutocomplete implements IOpcionesAutocomplet ...

Using Angular to interpolate a string from a Kendo CellClickEvent in a separate component

Within my application, I am working with three main components: Component A: Connects component B and C Component B: Displays a grid of objects Component C: Shows detailed information when a row in the grid of component B is clicked +----------------- ...

Access an Angular 2 component through an email hyperlink including querystring parameters

I need to create a deep link with query string parameters for a component, so that when the link is clicked, it opens up the component in the browser. For example: exmaple.com/MyComponent?Id=10 I want to include a link in an email that will open the com ...

Angular/Typescript: develop a factory function that creates objects based on the parent class's properties

I'm currently working on implementing a factory method that can return classes dynamically, and here's my code snippet: getWidget<T extends WidgetBase>(componentName: string): Type<T> { switch (componentName) { default: ...

Bringing @angular/code into a directory that is not within an Angular project

Currently, I have an Angular 2 project folder with a separate service folder named "auth.service.ts" located outside of it. Within this service file, I am importing `Injectable` from `@angular/core`. However, due to the service being located outside of t ...

What is the best way to incorporate data from my Input field into my Vue.JS application's existing data structure

Struggling with integrating new users into my personal project, particularly in passing input values (userName and userAge) to the parent element for addition to playersData. Here is a sample code snippet from the child component: `<template> <d ...

How come the information I receive when I subscribe always seems to mysteriously disappear afterwards?

I've been working on a web project using Angular, and I've run into an issue with my code that's been causing problems for a while now. The problem lies in fetching data from a server that contains translations: getTranslations(): Observab ...

NextJS introduces a unique functionality to Typescript's non-null assertion behavior

As per the typescript definition, the use of the non-null assertion operator is not supposed to impact execution. However, I have encountered a scenario where it does. I have been struggling to replicate this issue in a simpler project. In my current proj ...

Set up a Pinia store with a specific data type

Note: I am a beginner in JavaScript I am currently working on synchronizing an object with a Pinia store and a Python REST API. My goal is to define a type just once without having to duplicate it in the store. export const useTicketStore = defineStore(&a ...

Methods for organizing consecutive elements within an array in Javascript/Typescript

Let's explore this collection of objects: [ { key1: "AAA", key2: "BBB" }, { key1: "BBB", key2: "CCC" }, { key1: "CCC", key2: "DD ...

TypeScript Definitions for Material-UI version 15

Is there a Material-UI v15 TypeScript definition file in the works? I need it for a project I'm working on and as a TypeScript newbie, I want to make sure the custom file I've begun is accurate. ...

No contains operator found in Material UI Datagrid

While working on a project, I utilized Material UI's datagrid and successfully implemented filters such as contains and isEmpty. However, I am struggling to find information on how to create a notContains filter. Does Material UI natively support this ...

What is the best way to incorporate v-divider components in between each v-list-item?

I'm attempting to create multiple v-dividers based on the number of answers I have, so that there is a divider for each answer (4). Following an example from the official documentation, I'm trying something like this but I seem to be stuck. Could ...

Press the button within the nested component to send information to the parent component through another intermediate child component

Can data be passed by clicking on a button in a nested child component, then passed to another child component one level above, and finally to the parent component? This is how my components are nested: Parent ----Child ---------Child 2 (with a button th ...

The issue of Undefined TypeError arises when using Angular HttpInterceptor and injecting any service

Issue: I'm facing a problem where I am unable to inject any service into the constructor of my HttpInterceptors. Every service I try to inject results in the error: TypeError: Cannot set property 'authenticationService' of undefined Even ...

Ways to include various inputs with chip

I am currently working on a project that involves implementing an email field using the chip component. However, I have encountered an issue where pasting multiple email values for the first time inserts them into the field successfully. But when I try to ...