What is the method for confirming whether an emit has been defined?

I have a button that can handle both short and long press events.

Before transitioning to emitters, I relied on function callbacks due to my background in React Native.

The typings I used were:

export type UsePressableEmits =
  | {
      (e: "press", event: Event): void;
      (e: "longPress", event: Event): void;
    }
  | {
      (e: "press", event: Event): void;
    };

However, the following code block is currently throwing errors:

function fire(event: Event) {
    firing.value = true;
    emit("press", event);
    firing.value = false;
}

function fireLongPress(event: Event) {
    firing.value = true;
    emit("longPress", event); // does not pass type checks
    firing.value = false;
}

The emit function I am using is generated from:

const emit = defineEmits<{
      (e: "press", event: Event): void;
      (e: "longPress", event: Event): void;
    }>()

Answer №1

Consider this alternative.

export type UsePressableEmits = {
  (e: 'press', event: Event): void
  (e: 'longpress', event: Event): void
}

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

Utilizing React Component Inheritance for Utilizing both Parent and Child Methods

Exploring Options After developing a fully functional component with state, props, and methods, I encountered an issue where the component needed to behave differently based on the operating system (iOS or Android). Initially, I used conditional statement ...

TypeScript - patiently anticipating the completion of nested for loops

Currently, I am working on a task that involves implementing two nested for loops in my code. The primary objective of the first loop is to make an API call, which is dependent on the IDs selected by the user. Unfortunately, the limitation of passing only ...

Footer Cell isn't showing up as expected within *ngFor loop in Mat-Table

I'm having trouble displaying the total sum at the bottom of my table. Despite following the steps outlined in the documentation exactly, it still doesn't seem to be working for me. Below you can find the code from my template: <table mat-t ...

Ways to improve the feedback for Typescript when dealing with the potential existence of a nested method

Recently encountered a critical bug that I believe could have been identified with the right TypeScript setup. Struggling to come up with a suitable title, so please bear with me. While initializing a widget app, similar to a chat app loaded by a parent a ...

Transition animations are not activated when reordering a list in Vue.js

After nearly a year of working with vue.js, I still struggle to grasp animations and transitions. Today, I made an effort to understand them better, but once again, I hit a roadblock – the transition just won't cooperate, leaving me puzzled about wh ...

What makes utilizing v-for distinct from individually placing each item in this instance? Additionally, let's discuss how Bootstrap facilitates content centering

Playing around with my newfound understanding of Vue and Bootstrap, I encountered a puzzling behavior that left me stumped. <div class="col-sm-4" class="text-center"> <p v-html="message"></p> <button v-for="type in playTypes" ...

Vue js throws a maximum call stack error when updating a Chart component

I have successfully created a line chart using the Chart.js 3.5 library. The chart is responsive, all animations are working fine too. I am currently facing an issue where I am attempting to update the data from a parent component and trigger a chart updat ...

Revamp your search experience with Algolia's Angular Instant Search: Design a personalized search box template

Custom Search Box Request: My goal is to implement an autosuggest search box using Algolia Angular instant search with an Angular Material design. To achieve this, I am planning to customize the search box component by replacing the standard <ais-sea ...

Guide to sorting filtered results by date in Vue.js

We are excited to introduce a new events application that allows users to easily search for upcoming music festivals. To enhance the user experience, we aim to display filtered search results in chronological order based on the event's "startDate". O ...

Struggling to iterate through JSON data in Office Scripts?

My task involves parsing JSON data in Office Scripts to extract the headings and row details on a spreadsheet. While I have successfully fetched the data, I am encountering an error message stating that my information is not iterable at the "for" loop. ...

A secure way to perform a deep update on any type, even if it is completely different from the original

Is there a method to eliminate the as any in the update_substate function? It seems type-safe when directly invoking the update_state function, so it should also be safe when invoked indirectly, right? These functions are meant to be lightweight helpers ...

When attempting to register a custom Gamepad class using GamepadEvent, the conversion of the value to 'Gamepad' has failed

I have been working on developing a virtual controller in the form of a Gamepad class and registering it. Currently, my implementation is essentially a duplicate of the existing Gamepad class: class CustomController { readonly axes: ReadonlyArray<nu ...

Error message: Node package 'Typescript' could not be found

I've been working on setting up a project using Node and TypeScript. Unfortunately, I can't seem to figure out what's causing my settings to not work properly. I've tried different options for tsconfig/nodemon but nothing seems to be c ...

Having trouble displaying nested routes in Angular within the view

I'm encountering some issues with child/nested routes in Angular 4. In the app.module.ts file, my imports statement looks like this: RouterModule.forRoot([ { path: 'templates', component: TemplateLandingC ...

What is the correct way to utilize top-level "await" within TypeScript in Next.js?

One issue I encountered was when attempting to use "await" at the top-level like this: const LuckyDrawInstance=await new web3.eth.Contract(abi) A warning popped up in the terminal indicating to set experiments.topLevelAwait to true. However, even after t ...

Define the interface for a GraphQL resolver argument in code-first implementation

This specific GraphQL schema example from the Constructing Types page showcases how to define the Query type. // Creating the Query type var queryType = new graphql.GraphQLObjectType({ name: 'Query', fields: { user: { type: userType ...

Help me figure out how to independently toggle submenus on my navbar by utilizing the Vue.js composition API

I am currently working on developing a navbar using the Vue.js composition API. My primary objective is to toggle the submenus when a user clicks on them. However, since I am iterating through an object to display the submenus, I am faced with the challeng ...

The Angular4 router.navigate function appears to be unresponsive and fails to perform any actions

I have implemented conditional navigation based on the customer's role in the system. Here is an example of how it works: this.GetQuickStartStatus() .subscribe(data => { if(data.isActive){ ...

I am finding the event naming conventions in Vue 3 to be quite perplex

In the parent component, there is a child component: <upsetting-moment-step :this-step-number="1" :current-step-number="currentStepNumber" @showNextStep="showNextStep" ></upsetting-moment-step> The par ...

What is the best way to identify errors in an express listen callback function?

My current code is set up to verify if there was an error while initiating Express: express() .listen(port, (err: Error) => { if (err) { console.error(err); return; } console.log(`Express started`); ...