Dealing with Error TS2769 in Visual Studio Code when passing props to a custom component in Vue 2 with Typescript

I've encountered an issue with a Vue JS component that involves passing a custom prop. I am utilizing the Vue Options API without utilizing the class component syntax.

Whenever I pass ANY prop to my custom component the-header, I receive an error stating that typescript cannot recognize the overload on my component.

This error occurs regardless of which prop I try to pass, so it seems like there is something incorrect in my implementation.

Below is a minimal example, and I would greatly appreciate any assistance!

// App.vue
<template>
  <v-app>
    <the-header
    :first_name='user.first_name'
    />
  </v-app>
</template>
<script lang="ts">
import Vue from 'vue'
import TheHeader from './components/UI/TheHeader.vue'
export default Vue.extend({
  components: {
    TheHeader,
  },
  computed: {
    user (): User {
      return this.$store.getters['user/getCurrentUser']
    },
  },
})
</script>
// TheHeader.vue
<template>
  <nav>
    <v-app-bar
    app
    class="header">
  </nav>
</template>
<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
  name: 'TheHeader',
  props: {
    first_name: {
      type: String as Prop<string>,
      default: 'User'
    },
  },
})
</script>

My tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "jest",
      "node",
      "vuetify"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/unit/*.ts",
    "tests/unit/*.tsx", 
    "tests/unit/setup/shims-vue.d.ts"
  ],
  "exclude": [
    "node_modules",
    "src/**/*.js",
    "src/**/*.jsx",
    "tests/**/*.js",
    "tests/**/*.jsx",
    "tests/e2e/*.ts",
    "tests/e2e/*.tsx"  
  ]
}

Error Message:

No overload matches this call.
  Overload 1 of 3, '(options?: ThisTypedComponentOptionsWithArrayProps<{ links: { route: {
 name: string; }; text: string; icon: string; }[]; } & { logout(): void; } & { user: User; 
registeredSince: string; } & { id: number; value: boolean; } & Vue, object, object, object,
 never> | undefined): CombinedVueInstance<...>', gave the following error.

  Overload 2 of 3, '(options?: ThisTypedComponentOptionsWithRecordProps<{ links: { route: {
 name: string; }; text: string; icon: string; }[]; } & { logout(): void; } & { user: User; 
registeredSince: string; } & { id: number; value: boolean; } & Vue, object, object, object,
 object> | undefined): CombinedVueInstance<...>', gave the following error.

  Overload 3 of 3, '(options?: ComponentOptions<{ links: { route: { name: string; }; text: 
string; icon: string; }[]; } & { logout(): void; } & { user: User; registeredSince: string;
 } & { id: number; value: boolean; } & Vue, DefaultData<{ ...; } & { ...; } & { ...; } & { 
...; } & Vue>, DefaultMethods<...>, DefaultComputed, PropsDefinition<...>, DefaultProps> |
 undefined): CombinedVueInstance<...>', gave the following error. (ts2769)

Answer №1

If you want to specify a prop type, you can utilize the PropType helper that is imported from the 'vue' library:

import Vue,{PropType} from 'vue'
export default Vue.extend({
  name: 'TheHeader',
  props: {
    first_name: {
      type: String as PropType<string>,
      default: 'User'
    },
  },
})

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

How can I modify my Axios Post request to receive a 201 status code in order to successfully save the data?

I am facing an issue when attempting to make a POST request locally with Axios on my NodeJS front-end app to my .NET core local server. The server returns a 204 status code and the axios request returns a pending promise. How can I change this to achieve a ...

Troubleshooting undefined results when dynamically loading JSON data with $scope values in AngularJS

My input field is connected to the ng-model as shown below. <div ng-app="myApp" ng-controller="GlobalCtrl"> <input type="text" ng-model="FirstName"> {{FirstName}} </div> In my controller, console.log $scope.FirstName shows m ...

Unable to load the v-select component in the HTML page

My goal is to create a simple website where users can select options from a dropdown menu. I am currently using the Select.vue component from the vue-strap library for this task. However, I am facing an issue where the v-select component is not being loade ...

What is the best way to incorporate a search feature within Bootstrap cards?

I've been struggling to incorporate a search feature within my bootstrap cards. Despite trying various online methods, none have proven successful for me so far. Below is my HTML code - any assistance in implementing a search filter into my app would ...

The onChange function is not triggered when the dropdown menu consists of only one item

I am facing an issue with my dynamically populated dropdown menu. When the dropdown contains only one element, the onChange() function of my select tag does not work as expected. It functions perfectly fine when there are multiple elements present. How c ...

Preventing memory leaks by harnessing the power of Node Streams and promises

I am trying to wrap node streams in an async function, but I'm concerned about potential memory leaks in the following code. Will readStream and result be properly garbage collected after the promise is resolved or rejected? If not, what steps can I t ...

Issue with Tailwind classes not applying correctly upon refreshing the page in production settings

Challenge Description: Encountering an issue with my nextjs project that utilizes tailwindcss. The login page initially loads with the required classes for the UI, but upon refreshing the page, the classes disappear from the DOM, causing a broken UI. Her ...

Navigating the Path: Strategies for Caching Server-side Rendering in Next Js

I recently developed a Next JS Project along with a REST API implemented in PHP. My website is heavily reliant on API requests, which has prompted me to consider caching certain data points. I want to minimize the frequency of API requests for improved ef ...

Triggering a keyboard *ENTER* event on an Input in Javascript/React by clicking a button is a common query among developers

I am facing a challenge with an Input element that only displays results when I press Enter on the keyboard. The element is part of a third-party extension, so my control over it is limited. My goal is to trigger the ENTER event for the Input when a button ...

Nest may struggle with resolving dependencies at times, but rest assured they are indeed present

I've encountered a strange issue. Nest is flagging a missing dependency in a service, but only when that service is Injected by multiple other services. cleaning.module.ts @Module({ imports: [ //Just a few repos ], providers: [ ServicesService, ...

Watch for event triggered after completion of input field with ng-modal

One of my challenges involves implementing a text input field that prompts users to enter their name: <input type="text" ng-modal="form.name" placeholder="Enter NAME"> I've also set up a watch function to monitor changes in the form's nam ...

Material UI AppBar displaying custom colors instead of theme colors

Currently, I am utilizing Material UI version 4.7.0. In my project, I have established a customized theme (shown below) by utilizing createMuiTheme() method with personalized primary and secondary colors set. Within my AppBar component (also displayed be ...

Update of component triggered only upon double click

I'm encountering an issue with my parent component passing products and their filters down to a subcomponent as state. Whenever I add a filter, I have to double click it for the parent component to rerender with the filtered products. I know this is d ...

Oops! There was an issue trying to solve the command "/bin/bash -ol pipefail -c npm run build" while deploying a Next.js app on Railway. Unfortunately, it did not complete successfully and returned an exit code of

[stage-0 8/10] RUN --mount=type=cache,id=s/8a557944-4c41-4e06-8de9-06bfcc5e8aaf-next/cache,target=/app/.next/cache --mount=type=cache,id=s/8a557944-4c41-4e06-8de9-06bfcc5e8aaf-node_modules/cache,target=/app/node_modules/.cache npm run build: 17.62 17.62 ...

The Angular filter is waiting for the ng-repeat to be populated

I have a filtering system that includes dropdown options to filter the displayed content. The content is fetched from a database and takes a few milliseconds to display. During this time, I encounter several errors related to the filtering system. Does any ...

Update the user information by using its unique identifier at a specific location

I am currently working on editing user data with a specific MongoDB instance. When I click on the user's details, a modal popup appears with an update button below it. My goal is to have the user data updated when this button is clicked for the partic ...

Extending Interfaces Using Keys from an Array in Typescript

When dealing with a scenario where you want a pointfree omit, you can achieve this: type PlainObject<T> = {[key: string]: T} const omit = <K extends string>( name: K ) => <T, U extends PlainObject<T> & { [P in K]: T }>( ...

The TinyMCE editor's input box lost focus while on a popup dialog

Whenever I attempt to access the TinyMCE editor in a dialog box popup and click on "Insert link", the "Insert link" dialog box pops up but I can't type anything into the text field. I suspect that the issue may stem from having a dialog box open with ...

Modifying an item within an array of Mongoose models

I am working with a model schema that looks like this: { _id: foo cart: { items: [ { id: number name: string, } ] } } My goal is to locate the document by its id and then modify the name value of the object in ...

Exploring the functionality of componentWillReceiveProps within functional components

Embarking on my journey with functional components after extensively working with class components. While experimenting, I encountered a challenge: how can I incorporate the functionality of componentWillReceiveProps within the context of the useEffect h ...