Error message in Typescript: Types of variables 'el' and 'el' are not compatible. This issue is related to the Vue 3 composition API

I am encountering an issue while trying to utilize transition JavaScript Hooks in vue.js. The problem arises when I try to implement the @before-enter hook as described in the Vue documentation here: https://v3.vuejs.org/guide/transitions-enterleave.html#javascript-hooks

In the component's HTML, I have the following code snippet:

<transition name="fade" @before-enter="beforeEnter">
   <ul v-show="show">
      <p>hoge</p>
   </ul>
</transition>

And in the component's TypeScript file, I define the beforeEnter function like this:

const beforeEnter = (el:HTMLElement)=> {
    el.style.height = '0';
}

However, upon implementing this code, I receive the error message:

Type '(el: HTMLElement) => void' is not assignable to type '(el: Element) => void'.
  Types of parameters 'el' and 'el' are incompatible.ts(2322)

Can anyone help me figure out a solution to resolve this error?

Answer №1

The function handler produces a more generalized type. You may have to perform a cast.

const beforeEnter = (el:Element)=> {
    const hel = el as HtmlElement
    // const hel = el as unknown as HtmlElement
    hel.style.height = '0';
}

Trying to update your dependencies could potentially resolve the issue.

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

The API for GridOptions in Angular4's ag-Grid is not defined

Currently, I am utilizing the complimentary Version of ag-Grid within my Angular 4 Application. In this code snippet below, my intention is to automatically resize the grid within the constructor: constructor(private modalService: NgbModal) { this.gri ...

Exploring the Benefits of Using Relative Image Paths in Angular 2 and ASP.NET Core

I'm having trouble locating the relative paths for local image files in Angular 2. Typically, I would access them from the wwwroot/images folder, but when I try to load them from there it doesn't work. Where can I find the relative paths in Angu ...

TypeScript - create an Interface that must have either the error field or the payload field, but

My Action type has the following requirements: MUST have a field type {String} CAN include a field payload {Object<string, any>} CAN include a field error {Error} Constraints: IF it contains the field payload THEN it cannot contain the field er ...

Customizing datasource configurations for a loopback4 application based on specific environments

Embarking on my inaugural loopback project, I have opted for the loopback4 version. This server application is designed to interface with databases (Redis and MongoDB) and interact with external API services in a micro-service architecture. Currently, my ...

Type of parameter that changes based on certain conditions

I need help with a coding snippet interface IProps { isEdit: boolean; menuOpenId: number | boolean } function useMenuForm({ isEdit, menuOpenId }: IProps){...} Any suggestions on how to set menuOpenId as type number when isEdit is true, otherwise keep ...

VueJS validation not triggering on initial call

So, I've implemented a validation function triggered on blur from an input box. The method takes the ID and limits to be validated against as parameters. I'm utilizing Bootstrap Vue for the popover where the validation errors are shown. However, ...

The date appeared correctly in the code, but it did not get stored in the database

please add a photo I am attempting to store the current time in my database using my application. Unfortunately, instead of inserting the correct time, an empty date string is being saved. Can someone help me troubleshoot this issue? ...

Using TypeScript, define a React function component by specifying its name as a type

While working in React.js, I encountered an issue with my Function Component. When I attempted to use the function name as the type, it resulted in an error. Here is a snippet of the code: import * as React from "react"; import { render } from "react-dom ...

Invoke the router function dynamically

I am looking for a way to simplify route registration without manually writing out app.get('/', function (req, res, next) { }); each time. I want to automate this process by passing in a router object like the one below... { path: '&ap ...

Combining observation arrays with RxJS!

Displaying a concise overview of dates is the goal here (a simplified example provided). someArray$: Observable<Date[]> = of( new Date(2019, 11, 1), new Date(2019, 11, 2), new Date(2019, 11, 3)); Following that, a backend call retrieves data in thi ...

What is the location for adjusting the angular strictness flags that determine the level of strictness for strictTemplates?

Currently in the process of transitioning our application to strictTemplates, we are encountering a multitude of errors, some more significant than others. As a result, I decided to adjust the strictness of the angular type checker and came across these s ...

Steps to resolve the issue of being unable to destructure property temperatureData from 'undefined' or 'null' in a React application without using a class component

CODE: const { temperatureData } = state; return ( <> <div className="flex flex-row"> {temperatureData.map((item, i) => ( <div className="flex flex-auto rounded justify-center items-center te ...

Looking for a type that combines multiple options

I am interested in incorporating union types as function arguments, with the ability to utilize the arguments and have any missing ones default to undefined. However, when it comes to 'name' and 'age', there seems to be a type conflict ...

The ffmpeg.load() function is being awaited, but the overlay.ts file is throwing an Uncaught ReferenceError: document is not defined

I am currently using the FFMPEG plugin in conjunction with Vue3 and Vite. Here is my code: <script setup> import { FFmpeg } from '@ffmpeg/ffmpeg' import { fetchFile, toBlobURL } from '@ffmpeg/util' import {onMounted} from "vu ...

Discover how to reference a ref from a different component in Vue 3

I have multiple components that I utilize in a component named QuickButton.vue: <Tabs> <TabPanels> <TabPanel><EmployeesMainData/></TabPanel> <TabPanel><ContactAddressData/></TabPanel> ...

Using SCSS aliases in a Vue single file component with the help of Rollup

Adding an alias for SCSS files in a Vue SFC when using Webpack is straightforward. For example: <style lang="scss"> @import "~scss/config/config"; ... </style> This is how you would do it in Webpack: alias: { sass: path.resolve(__dirname, ...

Parsing a Json object that contains a field with two distinct types, one of which is recursive

In my project, I have a TypeScript component that retrieves JSON data, and I need to parse this JSON in C# to work with the objects. However, due to the presence of: multiple type fields recursion it's becoming challenging to understand how the dese ...

Tips for defining a key: reducerFunctions object within a Typescript interface

Exploring the given interface: interface TestState { a: number; b: string; } My goal is to create a generic type that enforces an object to: have the same keys as a specified interface (e.g. TestState) for each key, provide a value of a reducer funct ...

Trouble arises when trying to use Kendo-UI's Edit template alongside Vue's Single File Component

Utilizing the Kendoui grid Vue wrapper, I discovered in the Kendoui Vue documentation that a single file Component can be used for Kendo templates. Currently, I am working on an editable grid with a popup editor. In my attempt to set the "editable" propert ...

Encountering an issue saving files in Angular 2 when the npm server is active

Encountering an issue when trying to save .ts or .html files while npm is running 1: DoJoin(aka DoJoin) [native array.js:~129] [pc=0000035BB365DBB2] (this=0000005A3F604381 <undefined>,w=000003CB8840CFF1 <JS Array[104]>,x=104,N=0000005A3F6 ...