microsoft / microsoft/TypeScript
an emitter with 239 events breaks type check, throw ts2590 Expression produces a union type that is too complex to represent
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Bug Report
I wrote a framework (namely koishi) which uses a fully-typed event emitter implemented by itself. However when I create more events (totally 239), the type check just broke with an error ts2590 (Expression produces a union type that is too complex to represent). It seems that the error was thrown here:

I know 239 events is a lot, but I still cannot figure out how the 239 events became "100000 type checks".
Can you help prevent this error either by optimize type check performance or by improve my code? Thanks.
🔎 Search Terms
union type, interface, event emitter, ts2590
🕗 Version & Regression Information
I tried with v4.1.3, v4.1.5 & v4.2.1-rc. They all failed.
⏯ Playground Link
This playground will not work because it imports a dependency @octokit/webhooks-definitions (it's just a simple collection of github webhooks type definitions, but it is too big (over 5000 lines) to be included as I thought).
Playground link with a dependency
And the dependency code can be found here: https://unpkg.com/@octokit/webhooks-definitions@3.60.0/schema.d.ts
💻 Code
interface EventMap extends SessionEventMap, WebhookEventMap {}
declare function on<K extends keyof EventMap>(name: K, listener: EventMap[K]): () => boolean
on('message', () => {})
🙁 Actual behavior
TS2590 error: Expression produces a union type that is too complex to represent.
🙂 Expected behavior
No compiler error
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el Playground enlazado y el ejemplo mínimo de EventMap/on; después inspecciona la dependencia referenciada @octokit/webhooks-definitions schema.d.ts para reproducir TS2590 con aproximadamente 239 eventos. Compara las versiones de TypeScript indicadas y confirma que el ejemplo pasa la comprobación de tipos sin el error de complejidad de la unión.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100