microsoft / microsoft/TypeScript

Enhance user experience in face of false-positive type errors and type loss

Aperta
#53,977 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs Proposal Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Suggestion

A common source of frustration is false-positive type errors and cases when typing is lost. There are understandable reasons for limitations of the inference algorithm, but the sheer number of closed bug reports, features and stack overflow questions show that there is a big frustration around it.

I am referring to this: https://twitter.com/SeaRyanC/status/1544414378383925250

As a coder,

  • I would like to be able to figure out whether I ran into a limitation in the inference algorithm or a real type bug. That could be facilitated by including the complexity limits the algorithm ran into while coming up with the type error. As a bonus, the compiler could suggest to use typings if we are sure that it is a false positive.

  • I would like to be able to balance between the use of my brainpower spent on chasing false positives and the computing power spent on inference. That could be facilitated by making complexity limits configureable.

  • I would like to be able to provide utility functions to make life easier, to be able to express things more succintly, which requires complex typing. Loosing typing in those situations means that the resulting usage will be more verbose (like because type templates should be filled in by hand) than the expressions those functions meant to replace, making the effort useless. I see two kinds of helps in those cases:

    • increase complexity limits for specific type functions
    • make it possible to drive the inference algorithm for a type function in much the same way we drive the solver when doing formal verification.

I do understand that it is a lot of features, some of them might be insanely complicated to implement. I am more of talking about a change of approach than about features implemented right now. I believe that the current status where coders are frustrated, and the whole thing is blamed on Gödel is unsustainable.

🔍 Search Terms

a lot of closed issues and feature request, and also a lot of Stack Overflow questions show that this topic does create a lot of frustration.

I searched for "inference" in feature requests

✅ Viability Checklist

My suggestion meets these guidelines:

  • [ ✅ ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [ ✅] This wouldn't change the runtime behavior of existing JavaScript code
  • [ ✅ ] This could be implemented without emitting different JS based on the types of the expressions
  • [ ✅ ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • [ ✅ ] This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

  • configureable complexity of the inference algorithm
  • errors stating which inference limits they have ran into
  • ways to drive the inference algorithm exposed for type functions

📃 Motivating Example

When you run into a type error, the error message tells you what limitations the inference engine ran into, so it is easier to figure out whether it was a false positive or a real error.

You can set the limits of the inference engine in tsconfig.json, which you can increase to get rid of a false positive, and then it is your choice whether you wait more for the compiler to finish or use force-typing.

When you really need a type to be correct, you can drive the inference engine to achieve that without explosion of the decision space.

💻 Use Cases

My last false positive when Gödel got blamed. I do not believe it is that complex.
https://tsplay.dev/WJV6rW

A utility function (to work around the this idiocy of JS) with type loss:
https://tsplay.dev/NrQZ2w

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 i due esempi collegati di TypeScript playground, WJV6rW e NrQZ2w, e leggi i commenti della discussione sui casi segnalati di false-positive e type-loss. Poi esamina come vengono gestiti i limiti dell'inferenza e le funzioni di tipo di TypeScript; l'issue propone diverse direzioni possibili, quindi non è definito un criterio concreto di completamento.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.