Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

How to declare type of event parameter when listen for event

オープン
#188 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
ドキュメント
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
nuxtjs, typescript

調査の方向性

plugins/event-bus.ts と issue に示されている mitt の listener 呼び出しから始め、次に mitt の TypeScript 宣言と関連するドキュメントを読みます。報告されているイベントパラメーターの型付けをこの用途でサポートまたはドキュメント化できるかどうかを判断します。サポートされるアプローチまたは制限が明確に記録され、例の型エラーが解消または説明されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Hello,

I am using mitt 3.0.1 for my Nuxt app (nuxt 3.6.5). I use event-bus to emit/listen for the whole app:

File plugins/event-bus.ts

import mitt from 'mitt';

export default defineNuxtPlugin(() => {
  const emitter = mitt();

  return {
    provide: {
      event: emitter.emit, // Will emit an event
      listen: emitter.on, // Will register a listener for an event
    },
  };
});

I am currently not able to declare event when I listen for event in my components. I have to use type "any" but this break out type safety rules.

$listen('component:display', (event: any) => {
  // here the param I want to declare a specific type rather than type "any"
  // like event: {id?: string; value?: string}
});

I already tried assigned a sepecific type but it throw error:

$listen('component:display', (event:{id?: string; value?: string}) => {
  //
});

ERROR: No overload matches this call.
  Overload 1 of 2, '(type: "*", handler: WildcardHandler<Record<EventType, unknown>>): void', gave the following error.
  Overload 2 of 2, '(type: "component:display", handler: Handler<unknown>): void', gave the following error.ts(2769)

It's now allowed to use flag @ts-ignore in my app so I don't know how to solve this now.
I search on document but it seems no mention about this so I hope to receive any advice on this.
Thank you so much.

主要言語
TypeScript
スター
11.9k
フォーク
490
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

developit/mitt のほかの issue

developit/mitt の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。