microsoft / microsoft/TypeScript

InitialOnly Utility Type

Aperta
#45,610 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Suggestion

I have found myself more and more often using a tri-state boolean approach in my code. By that I mean a boolean that has an inital value of null and will be reset to true or false

Currently we would do something like:

let example: boolean | null = null;

However, I find the use case when going to route is often a set it one time and null then being an invalid value.

An argument may be why not use undefined well I believe the intentional aspect of setting it to null provides context and for more readable code. I also feel the creating of a tri-state enum wouldn't be the correct approach as well.

A utility type stating a value is acceptable only as an initial value and not on reassignment is the request.

🔍 Search Terms

tristate boolean, utility state

List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.

utility type, tri-state boolean

✅ 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

Utility type for a value only being acceptable on initialization.

📃 Motivating Example

I would talk about a tri-state boolean example.

💻 Use Cases

Work arounds were mention in main description.

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

Non sono indicati file sorgente, test o punti di ingresso. Inizia esaminando gli obiettivi di progettazione di TypeScript e il tipo utility proposto, limitato alla sola inizializzazione, quindi individua l’area rilevante del sistema dei tipi. Il lavoro sarà completo quando saranno disponibili un comportamento preciso del controllo dei tipi e test che dimostrino la differenza tra inizializzazione e riassegnazione.

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.