How to declare type of event parameter when listen for event
まだ誰も着手していません。
評価
- 難易度
- 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 はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
developit/mitt のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 48/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 1/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
似ている issue
-
blocklist removal
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
MetaMask/eth-phishing-detect#296544 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
pastelsky/bundlephobia#1122 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
category/development priority/P2 scope/file-operations scope/testing type/enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100