Vue 3 app encountering error due to element having an 'any' type implicitly

I want to incorporate lucidev icons into my component, but I am fairly new to typescript.

You can find the lucidev icons here: https://github.com/lucide-icons/lucide

<template>
  <component :is="icon" />
</template>

<script lang="ts">
import * as icons from 'lucide-vue-next';
import { defineComponent } from 'vue';

export default defineComponent({
  props: {
    name: {
      type: String,
      required: true,
    },
    size
  },

  computed: {
    icon() {
      return icons[this.name];
    },
  },
});
</script>

However, I am encountering an issue where I receive an error message stating that "element implicitly has an 'any' type because expression of type 'string' can't be used to index type in icons[this.name]". How can I resolve this problem?

icons:

https://i.sstatic.net/SUOdz.png

Answer â„–1

If you are encountering this error, it could imply that the icons variable does not match the expected type.

Typically, this issue arises when the variable is an array. In such cases, attempting to use a string as an index for the array will result in an error because it requires a number, like so: icons[2].

I suggest logging the icons variable to view its contents and determine the correct method for indexing it :)

Hopefully, this explanation provides some clarity!

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

What is the best way to attach a CSS class to a button in Vue by using the "or" condition

Can you explain the correct way to use or in v-bind:class in vue js? <a class="button btn btn-default is-info" style="float:right;" v-on:click="clearSearchItem" v-bind:class="{'disabled': searchItem=='&a ...

Vue.Js for a Single Page Application utilizing Two Data Sources

Currently, I am working on developing a Single Page Application using vue.js. My project consists of 2 bundles of pages stored in separate S3 buckets - one public and one private. The public bundle is meant to be accessible to all users, while the private ...

Union types discriminate cases within an array

Creating a union type from a string array: const categories = [ 'Category A', 'Category B' ] as const type myCategory = typeof categories[number] myCategory is now 'Category A' | 'Category B' Now, the goal is ...

Transition and transition-group animations in Vue.js do not seem to be functioning correctly

Having trouble implementing CSS transitions between slides in a Vue 2 Carousel component. Slides are created using v-for and shown/hidden using v-show. Attempted to use <transition> with mode=out-in, but encountered issues with two slides displaying ...

Using React Material UI in VSCode with TypeScript significantly hampers autocompletion speed

When including the "@mui/material", Visual Studio Code may become unresponsive, leading to Typescript warnings appearing after 10-15 seconds instead of the usual less than 10 milliseconds. For example: import { Button } from '@mui/material&a ...

The Vetur package in VScode is experiencing compatibility issues with user snippets functionality

Hey there! I'm currently utilizing VScode with the Vetur extension for Vuejs syntax highlighting and auto complete support. I've been attempting to make some user snippets function with Vetur by adding them to the vue.json file, but so far, it&ap ...

Combine an array of objects that are dynamically created into a single object

Having trouble transforming the JSON below into the desired JSON format using JavaScript. Current JSON: { "furniture": { "matter": [ { "matter1": "Matter 1 value" }, { "matter2": "Matter 2 value" }, { ...

What exactly is the function of the NextPage feature in Next.js?

Recently, I began incorporating TypeScript into my Next project. Could someone clarify the purpose of the following code snippets for me? import { NextPage } from 'next'; export const Page: NextPage = () => {} After reviewing the documentation ...

Is there a way to obtain the current URL within the index.html file using Vue.js?

How can I retrieve the current URL in my index.html file using Vue.js? When using pure JavaScript in index.html, I am only able to obtain the URL of the initial page. In order to capture the URL of other pages, I need to refresh the page as the value of ...

Is it possible for Angular's `HttpClient` to use complex property types in the `.get()` generics aside from just `string` or `number`?

After spending an entire day researching the topic, I've hit a dead end. All my efforts have only led me to discover one thing—omission. None of the information I've come across mentions whether you can utilize non-simple types (such as string ...

The type 'function that takes in a CustomEvent and returns void' cannot be assigned to a parameter of type 'EventListenerOrEventListenerObject'

When I upgraded from TypeScript version 2.5.3 to 2.6.1, my custom event setup started giving me an error. window.addEventListener('OnRewards', (e: CustomEvent) => { // my code here }) [ts] Argument of type '(e: CustomEvent) => ...

Keep your Vue site/PWA fresh and up-to-date with automatic updates for every new release

My Vue application serves both as a browser app and as a PWA. I want to make sure that users always have the most recent version of the app whenever updates are pushed to the server. My tech stack includes Nginx, Django, vue-cli, and @vue/cli-plugin-pwa. ...

Discovering duplicates for properties within an array of objects in React.js and assigning a sequential number to that specific field

I am working with an array of objects where each object contains information like this: const myArr=[{name:"john",id:1}{name:"john",id:2}{name:"mary",id:3}] In the first 2 elements, the "name" property has duplicates with the value "john". How can I updat ...

Error message: "An issue has been encountered within Angular 4 where it is

Thank you for any assistance, I realize this may be a beginner question... but I seem to be missing something and my TypeScript code is error-free. My goal is simple: I want to track which Main Menu Item is currently selected. To achieve this, I have bou ...

Is there a way to incorporate symbols such as @ in vue-i18n?

Currently, I'm utilizing vue-i18n to localize my forms. Within one of the form fields for email input, there is a placeholder that showcases an example email address with an "@" symbol included. emailPlaceholder: 'eg: <a href="/cdn-cgi/l/email ...

I am encountering a challenge when trying to invoke a different function within the Facebook login callback in my

In my Vue2 application, I have implemented a login system using Facebook login. This system captures the access token from the Facebook API and sends it to the backend for processing user data. When the user clicks on the "login with Facebook" button, the ...

Using $emit in VueJS to set exclusive active components

I'm facing a challenge with setting unique active Components using $emit in VueJS. My goal is to have Tab A become active when clicked on in the tabbar component, without affecting the activation status of Tab B, and vice versa for Tab B. I apprecia ...

Comparing "const" and "Vue.component": Understanding the Distinctions

I am new to the world of Vue framework and finding myself struggling with the basics. Currently, I am facing a challenge in creating reusable components. My current approach to creating these components is as follows: Vue.component('SomeReusableComp ...

The table is failing to display the values contained within the array

My users list is successfully retrieved from the API and I can see the data in my console. However, when I attempt to map it and display it as a table, it doesn't seem to work as expected. This is the component I'm working with: interface IUser { ...

The element class type 'xxx' is lacking several properties compared to the 'ElementClass' type, including context, setState, forceUpdate, props, and others. This issue is flagged with error code TS2605

Encountering an error while attempting to execute my react app: D:/React/my-components/src/App.tsx TypeScript error in D:/React/my-components/src/App.tsx(23,4): JSX element type 'Confirm' is not a constructor function for JSX elements. ...