microsoft / microsoft/TypeScript
Better printing of `T & U` where this is equivalent to `Extract<T, U>`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
Suggestion
🔍 Search Terms
Extract intersection union ide editor printing
✅ 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
There are many cases where T & U is equivalent to Extract<T, U>. However, the former has much worse type printing in these cases than the latter, leading to a much worse developer experience for this case.
I initially raised this as an eslint rule, but it would be very difficult to do do from that side (as explained in the comments of https://github.com/typescript-eslint/typescript-eslint/issues/2983
📃 Motivating Example
type A = Action & { type: 'action1' | 'action2' }
// ({
// type: 'action1';
// a: number;
// } & {
// type: 'action1' | 'action2';
// }) | ({
// type: 'action2';
// b: string;
// } & {
// type: 'action1' | 'action2';
// })
type B = Extract<Action, { type: 'action1' | 'action2' }>
// {
// type: 'action1';
// a: number;
// } | {
// type: 'action2';
// b: string;
// }
💻 Use Cases
Improve developer experience, error messages, and IDE support.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit den motivierenden TypeScript-Beispielen und der verlinkten TypeScript Playground-Reproduktion. Untersuche das Verhalten der Typausgabe und der IDE-Unterstützung; als abgeschlossen gilt die Aufgabe, wenn äquivalente Schnittmengen in einer klareren Extract-like-Form dargestellt werden, ohne das Laufzeitverhalten zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- developer-experience
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100