andywer / andywer/typed-emitter

Type issue with listener parameters

Aberta
#41 1 comentário 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
JavaScript
Estrelas
285
Forks
29
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

I have an variable called "event" and it is type is `keyof Events`
```ts
// I have an variable called "event" and it's type is `keyof Events`
emitter.on(event, (...args) => {
// It says args is any[] but we know that it is parameter of any of Events
})
```

To fix this we can change type definitions.
Current type definition is:
```ts
on (event: E, listener: Events[E]): this
```
but if we change it with
```ts
on(event: E, listener: (...args: Parameters) => ReturnType): this
```
the problem gets solved, now TypeScript knows args is any of the Events

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.