microsoft / microsoft/TypeScript

an emitter with 239 events breaks type check, throw ts2590 Expression produces a union type that is too complex to represent

Aperta
#42,790 3 commenti 4 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: check: Big Unions Domain: check: Contextual Types Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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:

image

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il Playground collegato e l’esempio minimo di EventMap/on, quindi esamina la dipendenza referenziata @octokit/webhooks-definitions schema.d.ts per riprodurre TS2590 con circa 239 eventi. Confronta le versioni di TypeScript riportate e conferma che l’esempio supera il controllo dei tipi senza l’errore di complessità dell’unione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.