The type 'BusinessParameter[]' does not share any properties with the specified type

Within my API function, the return type is specified as

Promise<BusinessParameter[]>
because the expected outcome is an array of BusinessParameters. Despite assigning the same type to the variable where this result is stored (
returnOrderItemBusinessParameters: [] as BusinessParameter
), TypeScript is throwing an error that I cannot seem to pinpoint. This particular project uses Vue 3 with Pinia and Vue Apollo.

The error message I am encountering is as follows:

[vue-tsc] Type 'BusinessParameter[]' has no properties in common with type '{ __typename?: "BusinessParameter"; id?: number; entity?: string; type?: string; isRequired?: boolean; nameTranslated?: string; descriptionTranslated?: string; technicalName?: string; value?: string; dataArray?: any; }'.
/var/www/app/src/services/businessParametersService.ts:10:5
  
     8 |     const result = await businessParametersApi.getBusinessParametersForEntity('ReturnOrderItem')
     9 |
  > 10 |     returnOrderStore.returnOrderItemBusinessParameters = result
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    11 | }
    12 |
    13 | export { loadBusinessParameters }

Here is how the type definition for BusinessParameter is structured:

export interface BusinessParameter {
    __typename?: "BusinessParameter"
    id?: Maybe<Scalars["Int"]>
    entity?: Maybe<Scalars["String"]>
    type?: Maybe<Scalars["String"]>
    isRequired?: Maybe<Scalars["Boolean"]>
    nameTranslated?: Maybe<Scalars["String"]>
    descriptionTranslated?: Maybe<Scalars["String"]>
    technicalName?: Maybe<Scalars["String"]>
    value?: Maybe<Scalars["String"]>
    dataArray?: Maybe<Scalars["JsonObject"]>
}

The structure of my store includes

returnOrderItemBusinessParameters
, which stores an array of BusinessParameters:

import { defineStore } from 'pinia'
import { BusinessParameter } from '@/types/graphql/graphql'

export const useReturnOrderStore = defineStore('returnOrder', {
    state: () => ({
        returnOrderItemBusinessParameters: [] as BusinessParameter,
    }),
})

Below is a snippet depicting the API function itself (the response contains an array of BusinessParameters):

import gql from 'graphql-tag'
import { useLazyQuery } from '@vue/apollo-composable'
import { BusinessParameter } from '@/types/graphql/graphql'
import { OptionsParameter } from '@vue/apollo-composable/dist/useQuery'
import { defaultQueryOptions, getGraphQLEndpoint } from '@/services/graphQLService'

export default {
    getBusinessParametersForEntity(entity: string): Promise<BusinessParameter[]> {
        return new Promise((resolve, reject) => {
            const { load: loadBusinessParameters, onResult, onError } = useLazyQuery(gql`
                query getBusinessParameterClassifier($entity: String!) {
                    getBusinessParameterClassifier(entity: $entity) {
                        id
                        technicalName
                        nameTranslated
                        descriptionTranslated
                        type    
                        isRequired
                        dataArray
                    }
                }
            `)

            loadBusinessParameters()

            onResult(result => resolve(result.data.getBusinessParameterClassifier))
            onError(error => reject(error))
        })
    }
}

When the server responds to the API call, the data looks like this:

{
  "data": {
    "getBusinessParameterClassifier": [
      {
        "id": 8,
        "technicalName": "amount",
        "nameTranslated": "Amount",
        "descriptionTranslated": "amount",
        "type": "decimal",
        "isRequired": false,
        "dataArray": "[]",
        "__typename": "BusinessParameter"
      },
    ]
  }
}

Finally, here is the code portion where the API call is made and the resulting data is assigned to

returnOrderItemBusinessParameters
; however, it fails to perform due to the previously mentioned error:

const loadBusinessParameters = async () => {
    const result = await businessParametersApi.getBusinessParametersForEntity('ReturnOrderItem')

    // Error: Type 'BusinessParameter[]' has no properties in common with type '{ __typename?: "BusinessParameter"; id?: number; entity?: string; type?: string; isRequired?: boolean; nameTranslated?: string; descriptionTranslated?: string; technicalName?: string; value?: string; dataArray?: any; }'
    returnOrderStore.returnOrderItemBusinessParameters = result
}

Answer №1

The issue actually stemmed from a discrepancy in the category of products at my shop.

-returnOrderItemBusinessParameters: [] as BusinessParameter,
+returnOrderItemBusinessParameters: [] as BusinessParameter[],

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

Leveraging Vue Js directives within a component using vue-loader

I am currently facing an issue with vue-loader. I have created a directive in the main app.js to use in a component, but I am unable to implement that directive within the component. The error message I receive is: vue.common.js?e881:1014 [Vue warn]: Fai ...

VueJS computed property not updating correctly

My web application, built with Laravel / Vue JS, includes a google map component and a Vuetify data-table component. The Vue instance also features a computed property that calculates points for the Google Map based on another computed property from the Vu ...

Setting a default value for a data type within Typescript

My goal is to set default values for all properties in my custom type if they are not defined. This is what I have done: // custom type with optional properties type MyType = { // an example property: str?: string } // with numerous properties, assign ...

Get rid of the TypeScript error in the specified function

I am currently working on implementing a "Clear" button for a select element that will reset the value to its default state. Here is a snippet of my code: const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => { onChange( ...

Installing Yarn causes the download of an unconventional directory

Currently, I am facing an issue while trying to install yarn on my Macbook Pro (2017). The installation process seems to be downloading a folder called /react-praktis/ instead of completing successfully. Below is a screenshot for reference: https://i.stac ...

Angular TS class with an ever-evolving and adaptable style

Currently, I am working with angular 9. Does anyone know a way to dynamically change the CSS of a class in a component? .stick-menu{ transform: translate(10px,20px); } I am looking to dynamically adjust the position of x and y values. For example: .stic ...

Finding the imported function in Jest Enzyme's mount() seems impossible

I'm currently facing an issue where I need to mount a component that utilizes a function from a library. This particular function is utilized within the componentDidMount lifecycle method. Here's a simplified version of what my code looks like: ...

The origin of the Angular img src becomes blurred when invoking a function

I want to dynamically change the image src by calling a function that returns the image path. However, when I attempt to do so using the code below, the image element displays as <img src(unknown)/> component.ts: getMedia(row) { this.sharedData ...

Utilizing TypeScript to perform typing operations on subsets of unions

A TypeScript library is being developed by me for algebraic data types (or other names they may go by), and I am facing challenges with the more complex typing aspects. The functionality of the algebraic data types is as follows: // Creating ADT instatiat ...

Fill out FormBuilder using data from a service within Angular2

I am working with an Angular2 model that I'm filling with data from a service. My goal is to use this model to update a form (created using FormBuilder) so that users can easily edit the information. Although my current approach works, I encounter er ...

What could be causing TypeScript to throw errors regarding the initialState type when defining redux slices with createSlice in reduxToolkit, despite it being the correct type specified?

Here is my implementation of the createSlice() function: import { createSlice, PayloadAction } from "@reduxjs/toolkit"; type TransferDeckModeType = "pipetting" | "evaluation" | "editing"; var initialState: Transfer ...

Tips for getting Nativescript listview to function properly

I am currently developing an app using nativescript and angular 2. I am facing some issues while trying to implement the nativescript listview component. Whenever I run the app, all I see is " [object object] ". Below is my view code : <grid-layout c ...

Incorporating external resources into Laravel

Though it may be an old question, I have never attempted it before and have been unable to find a solution (all the samples I found were in scss files). Currently, I am using JavaScript scaffolding as my front-end, so all I have in my layout assets is: & ...

TypeScript - Minimize redundancy when defining types for a class and its constructor arguments

Here is a class structure I am currently using: class Person { id?: string = uuid(); name: string; constructor(data: Person) { _.merge(this, data); } } The 'uuid' function generates an id and '_' refers to loda ...

What is the best way to declare and initialize a global variable in a TypeScript Node application?

When using Webpack: const WebpackConfig = { // ... plugins: [ new Webpack.DefinePlugin({ __IS_DEVELOPMENT_BUILDING_MODE__: isDevelopmentBuildingMode, __IS_TESTING_BUILDING_MODE__: isTestingBuildingMode, __IS_PRODUCTION_BUILDING_MO ...

Using the Promise function with callback to map the JSON payload object into an object

I received a JSON payload with the following structure: { "name": "Reports", "subject": "Monthly Reports", "attachments":[ { "attachment":{ "name": "Month1.pdf", "type": "application/pdf", "path": "h ...

"Encountering a 'No overload matches this call' error while attempting to utilize a Vue Component in TypeScript

While attempting to implement a child component in a TypeScript Vue Component, I encountered the error message "No overload matches this call". Sharing this for the benefit of others, as finding a solution online proved challenging. import {ChildCompone ...

Tips for resolving the issue of "The types 'GameState' and 'string' do not intersect, so this condition will always yield 'false'."

I need to display different components based on the value of gameStatus: import React from "react"; import { useAppSelector } from "./hooks/redux"; import EndScreen from "./pages/EndScreen"; import QuestionsPage from "./p ...

Creating dynamic components from JSON elements does not trigger a rerender of components within an array

Imagine having a simplified input structure like this: [ { type: "text", text: "how are you {name}" }, { type: "input", input: "name" }, { type: "text", text: "good to ...

Tips for typing the HTML tag as text inside a span element with Angular

When retrieving the value "Evidence" from an API, it looks like "<FORM METHOD="get" ACTION="search">" { data: { evidence:<FORM METHOD="get" ACTION="search"> } } In my TypeScript file: pub ...