microsoft / microsoft/TypeScript
Better printing of `T & U` where this is equivalent to `Extract<T, U>`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con gli esempi motivanti in TypeScript e la riproduzione collegata in TypeScript Playground. Analizza il comportamento della stampa dei tipi e del supporto dell’IDE; il lavoro sarà completo quando le intersezioni equivalenti saranno presentate in una forma Extract-like più chiara senza modificare il comportamento a runtime.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- developer-experience
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100