Vue3 and TypeScript encounter a problem where the attribute 'dataToggle' is not recognized on the type 'ElementAttrs<AnchorHTMLAttributes>'

Query

In my vue 3 application, I am facing an issue while trying to implement a bootstrap4 snippet for creating a nav bar menu -

      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
          aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>

However, the compiler is throwing the following error message -

Type '{ class: string; href: string; id: string; role: string; dataToggle: string; "data-toggle": string; ariaHaspopup: string; "aria-haspopup": "true"; ariaExpanded: string; "aria-expanded": "false"; }' is not assignable to type 'ElementAttrs'. Property 'dataToggle' does not exist on type 'ElementAttrs'.ts(2322)

Due to this error, the dropdown menu is not functioning properly...what could be causing this issue?

UPDATE Content of shims-vue.d.ts file -

declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}

Answer №1

Start by creating a new file called bs.d.ts and add the following content:

import "vue";

declare module "vue" {
  interface HTMLAttributes {
    dataToggle?: string;
  }
}

Be sure to include this file in your tsconfig.json.


For more information, check out the original answer at: How to augment `ElementAttrs<HTMLAttributes>` interface in Vue?

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

Is there a way for me to receive a unique selection of items from an array for every accordion item?

I am currently facing an issue where all three accordion items have the same set of objects, but I want each of them to have a different set. Here's what I have attempted so far, but it is not working as expected: const meetingRooms = [ { ...

Altering the background color of an individual mat-card component in an Angular application

Here is the representation of my mat-card list in my Angular application: <div [ngClass]="verticalResultsBarStyle"> <div class="innerDiv"> <mat-card [ngClass]="barStyle" *ngFor="let card of obs | async | paginate: { id: 'paginato ...

Choosing to selectively trigger a function using TypeWriter

I have successfully implemented TypeWriter to generate TypeScript classes from my C# models. The template I am currently using is shown below: ${ using Typewriter.Extensions.Types; Template(Settings settings) { settings.IncludeProject ...

Issue with typings in TypeScript is not being resolved

I have integrated this library into my code Library Link I have added typings for it in my project as follows Typings Link I have included it in my .ts file like this import accounting from "accounting"; I can locate the typings under /node_modules ...

Data not reflecting changes in component when field is modified?

I currently have a table on my web page that displays data fetched from an array of objects. The data is collected dynamically through websockets by listening to three different events. User can add an entry - ✅ works perfectly User can modify ...

Challenges with setting up autoprefixer in Vue3

Recently, I commenced a new project using Vue-cli 3 with the command vue create my-new-project. In this project, I implemented CSS grid for certain layout aspects and it is imperative that I ensure compatibility with IE11 and newer versions. Despite the fa ...

Using the VSCode debugger to place a breakpoint within a Typescript package that has been symlinked using `npm link`

I'm currently troubleshooting a NodeJS application and its associated typescript packages, which have been linked using `npm link`. The directory structure is as follows: /root/package-a # typescript package /root/package-b # another typescript packa ...

Dealing with Undefined Issue in Angular Subscription Validation

Let me start by acknowledging that while there are numerous questions on this topic, none of them addressed the specific issue I encountered. Despite trying various approaches with maps and other methods, I am still unsure about the correct way to proceed. ...

Unable to render Material Icons on Vue/Quasar web app hosted on Azure

I am facing an issue with my webapp built using Vue and Quasar. I added the necessary icon imports to my quasar-user-options.js file. import '@quasar/extras/material-icons/material-icons.css' import "@quasar/extras/material-icons-outlined/ma ...

Having trouble connecting my CSS Bootstrap file in VS Code

Having trouble linking my bootstrap file to my HTML in VS Code. Despite successfully adding the link, it does not seem to be working. https://i.sstatic.net/Yt7VH.jpg ...

Rule of authentication using Firebase Database

I need to establish a rule in my Firebase Database to prevent unauthorized access for reading and writing purposes. Within my database, there is a collection of words, each containing a "uid" field that corresponds with the uid of the authUser key stored ...

What is the best way to retrieve data from within a for loop in javascript?

Seeking assistance in Typescript (javascript) to ensure that the code inside the for loop completes execution before returning I have a text box where users input strings, and I'm searching for numbers following '#'. I've created a fun ...

ES6: The attribute 'selected' is not found on the data type 'Object'

While attempting to convert the JS code from 'AMcharts4 codepen pre selecting areas' into ES6, I encountered an error. Error TS2339: Property 'selected' does not exist on type 'Object'. Here is the code snippet that I am l ...

Encountered an issue when utilizing the useRef hook in Next.js version 13

I am currently exploring nextjs13 and typescript. I encountered an issue when attempting to use the useRef hook. Below is the code snippet in question: import { useEffect, useRef } from "react" export const useDraw = () => { const canvas ...

Do not use a template for keying. Instead, place the key directly on physical elements

I'm trying to incorporate the image preview feature using the image component within the View Design framework, but I keep encountering an error. You can find the Component url here under Example 5. Below is the code snippet: <template> < ...

Having difficulty displaying TIFF images and incorporating them into a Fabric Object

I have gone through the tutorials available at: and also familiarized myself with the Fabric Objects documentation. While I was successful in loading JPG and PNG images onto the canvas, my current project requires me to load TIFF images and apply filters ...

Using Typescript to add an element to a specific index in an array

Currently, I am engaged in a project using Angular2 and Firebase. My goal is to consolidate all query results under a single key called this.guestPush. Within my project, there is a multiple select element with different user levels - specifically 4, 6, ...

Arrange the div underneath the link in Vue.js

I have a collection of dynamic hyperlinks generated in Vue.js <a class="block" href="#" @click="toggleNavigation(item)" v-for="item in skills" :key="item.id">{{item.name}}</a> and a Container that is placed absolutely <div style="position ...

Having trouble accessing @ViewChildren from the parent component

I've been facing an issue while attempting to control the child instances of a component and I can't seem to bypass this particular error. I've been referring to solutions provided on this specific thread. The main component Sequence houses ...

Achieving the ideal HTML layout for small screens that differs from larger screens is a common challenge faced by web developers

After implementing the markup code, I achieved the desired layout on large screens. However, when reducing the screen size to a phone level, I require a layout similar to image-3, and on larger screens like laptops, it should resemble image-1. Image-1 and ...