microsoft / microsoft/TypeScript

Change default inference from arrays to tuples and primitives to literals

Offen
#38,831 18 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

I am working on functional project now and I'm getting a lot of errors related to too wide type inference for values. It looks like

function test(a: { data: 1 | 2 }) { return a }
const a = { data: 2 }
// Types of property 'data' are incompatible.
// Type 'number' is not assignable to type '2'.ts(2345)
const b = test(a)

There're really many errors like this, and the main problem is that you can convert type A to type B, but not vice versa.

type A = { data: 2 }
type B = { data: number }

So, I ask you to add a new compiler option (to not break existing code) that will make type checker infer types as narrow as possible. It will be very helpful for functional programming.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Durchsicht der Dokumentation zum TypeScript-Typchecker und zu Compiler-Optionen und verwende die Array-, Primitiv- und Literal-Inferenz-Beispiele des Issues als erwartetes Verhalten. Lege zuerst den Geltungsbereich und die Kompatibilitätsregeln der Option fest; als abgeschlossen gilt die Aufgabe, wenn die angeforderte enge Inferenz funktioniert, ohne das bestehende Verhalten zu ändern, wenn die Option deaktiviert ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.