Unspecified type for 'props' parameter - a hurdle in Vue 2's composition API

I've hit a roadblock while attempting to integrate TypeScript into an existing Vue 2.6 project. Unfortunately, I'm required to stick with version 2.6 for legacy reasons. I've gone ahead and installed the composition API as a plugin.

The error I'm encountering is present in multiple components and presents itself in the following manner:

Parameter 'props' implicitly has an 'any' type.

Here is the code snippet that's causing the issue:

<script lang="ts">
import { reactive, computed } from "vue";

export default {
  name: "Avatar",

  props: {
    title: {
      type: String,
      default: "my title",
    },
    alt: {
      type: Boolean,
      default: false,
    },
    size: {
      type: String,
      default: "regular",
    },
  },

  setup(props) {
    props = reactive(props);
    return {
      classes: computed(() => ({
        avatar: props.title,
        "avatar--alt": props.alt,
        "avatar--small": props.size == "small",
      })),
    };
  },
};
</script>

The error specifically arises on the line where setup(props) { is declared.

While manually adding the type any to props within the setup function removes the error, I understand that this is not the ideal solution. Can anyone provide suggestions or a proper solution to this dilemma?

Answer №1

Vue 2.6 does not come with the composition api by default. I recommend upgrading to Vue 2.7, which includes it:

If upgrading is not an option and you are using the Vue 2 Composition API plugin, ensure that you are importing the correct components:

// use the APIs
import { ref, reactive } 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

Utilize style as a module in Angular

The issue at hand: Let's take a look at this project structure: /src /public /styles /general /tables.scss /secure /components /someTable1 /someTable.component.ts /someTable.component.css /someTa ...

Fixing the CORS issue that is causing errors in my Vue JS application

I am facing an issue with the front end in Vue and back end in Spring Boot. In the Spring Boot app, I have a controller with two endpoints - /api/v1/user/login (POST) and /api/v1/user/get (GET). The @CrossOrigin annotation has been added to the controller. ...

Why is my data not loading on the first try when both Vuex's mount() and computed() are executed in the same component?

Using the action, I retrieve all products and then utilize the computed method within the same component to display the data. Below is the structure of the component: <template v-for="product in allProducts"> <div class="ap-table-content"> ...

The missing properties in the TS Type are as follows:

Currently working with Angular 7.x.x and TypeScript version 3.2.4. I have defined two TypeScript interfaces where one extends the other: Main interface: export interface Result { var1: string; var2: number; var3: boolean; } The second ...

Utilize npm to construct a Vue application and execute it on a Raspberry Pi device

My roommate and I are currently working on a Vue app project together, and we're aiming to deploy it on our Raspberry Pi. We're wondering if there's a way to npm build the final app on our PC and simply start the server on the Pi without hav ...

Using Two Unique Typeface Options in Material UI for ReactJS

Currently, in my React App, I am utilizing the Material UI library with Typescript instead of regular Javascript. I've encountered a small hurdle that I can't seem to overcome. The two typefaces I want to incorporate into my app are: Circular-S ...

Tips for ensuring that CSS hover effects stay in place even when the page is scrolled

i'm having trouble with a project in React JS that I received from another team. I'm not very confident in my skills with React JS, and I'm facing an issue where a certain part of the page is supposed to change to red when hovered over. Howe ...

Can you explain the rule known as the "next-line" in TypeScript?

No code examples are available for the specific scenario described below: "next-line": [ true, "check-catch", "check-finally", "check-else", "check-open-brace", "check-whitespace" ], ...

Express Server Providers for Angular 17's Server-Side Rendering

I attempted to share my request and response object with the Angular application by defining Providers in the "server.ts" file. However, when injecting them into app.component, they always appear undefined regardless of whether I am in the server or clie ...

Navigating to the main directory in Angular 2

I am currently diving into the world of Angular 2 and attempting to create my very first application. I am following a tutorial from Barbarian Meets Coding to guide me through the process. Following the steps outlined in the tutorial, I have set up my appl ...

What is the best way to sort a union based on the existence or non-existence of a specific

My API response comes in the form of a IResponse, which can have different variations based on a URL search parameter. Here is how I plan to utilize it: const data1 = await request<E<"aaa">>('/api/data/1?type=aaa'); const d ...

Can you please explain how I can retrieve information from a Firebase collection using the NextJs API, Firebase Firestore, axios, and TypeScript?

I'm currently utilizing api routes within NextJS 13 to retrieve data from Firebase. The code for this can be found in api/locations.tsx: import { db } from "../../firebase"; import { collection, getDocs } from "firebase/firestore"; ...

The state of vuex does not reveal its length

Within the vuex state, there is a variable 'images' defined as an array. When I use console.log(state.images), it shows output in this format: [__ob__: Observer] 0: {…} 1: {…} 2: {…} 3: {…} 4: {…} length: 5 __ob__: Observer {value: Arr ...

Tips for using rspec to test front end functionality?

In my Rails project, I have incorporated Vue.js using only the core library. Currently, most forms in the project are developed with Vue.js. When testing front-end features like form filling or validations using feature tests in RSpec, I found it to be qui ...

Steps for adding transitions to Font Awesome 5 Vue Icons

I am trying to replace an icon and apply a transition effect. By using the vue-fontawesome npm package, I have configured my icon with computedIcon, which is a computed property that determines the icon to be displayed: <transition name="fade"> ...

Retrieving the chosen option using a change event listener

Is there a way to retrieve the selected option using a change listener in TypeScript? I have come across JavaScript examples where the value is retrieved through event., but I am unable to locate any field that contains the selected option. <!DOCTYPE ...

Ways to reset an input field when focused

Looking to implement a number input field in React that clears the initial value when the user clicks on it. While there are solutions available for text inputs, I have not come across a method for number inputs. Every attempt I make at solving this issu ...

Encountered an unexpected error in Vue: "Maximum call stack size exceeded callWithAsyncErrorHandling - Uncaught Range

<button onClick="test">Test</button> Issue encountered in Vue 3 that caused significant troubleshooting: Error message: Uncaught RangeError: Maximum call stack size exceeded callWithAsyncErrorHandling https://i.sstatic.net/sW2TU.pn ...

Unable to transfer data through Ionic popover

I've encountered an issue when trying to pass data to my popover component, as the data doesn't seem to be sent successfully. Code HTML <div class="message" id="conversation" *ngFor="let message of messages.notes"> <ion-row class= ...

Encountered an unexpected identifier error while executing a Nuxt.js project

I am utilizing the following technologies: Node.js version 6.14.2 NPM version 6.0.1 Ubuntu 16.04 Whenever I attempt to execute a project, I encounter the following error message: npm run dev node_modules/nuxt/lib/core/module.js:14 async ready( ...