microsoft / microsoft/TypeScript
InitialOnly Utility Type
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
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
Es werden keine Quelldateien, Tests oder Einstiegspunkte genannt. Beginne damit, die TypeScript-Entwurfsziele und den vorgeschlagenen Utility-Typ nur für die Initialisierung zu prüfen, und ermittle anschließend den relevanten Bereich des Typsystems. Erledigt wäre die Aufgabe, wenn ein präzises Typprüfungsverhalten sowie Tests vorhanden sind, die Initialisierung und Neuzuweisung demonstrieren.
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
- Muss geklärt werden
- Anfängerfreundlichkeit
- 20/100