microsoft / microsoft/TypeScript
strict boolean expressions compilerOption
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Search Terms
require strict boolean
Suggestion
add yet another --strict check into compilerOptions, to only allow expressions that evaluate to Boolean for all conditional branching - if, for, while, ?: ternary operator, etc
basically this TSLint rule, built into TS compiler
https://palantir.github.io/tslint/rules/strict-boolean-expressions/
Use Cases
often people check the existence of function, before calling it:
if (somFunc) someFunc()
or they think that function is actualy a property, and hence dont call it
if (someVal)... . where it should have been if (someVal()) ...
if if required a strict boolean expression, both of the above would have been errors.
Examples
instead above examples would be written:
if (!!someFunc) someFunc()
and for someValue():boolean
if (someValue())..
Checklist
My suggestion meets these guidelines:
- 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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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 der Überprüfung von TypeScripts Verarbeitung von compilerOptions und der Pfade der Typprüfung für if, for, while und bedingte Ausdrücke. Vergleiche das gewünschte Verhalten mit der verknüpften TSLint-Regel strict-boolean-expressions. Erledigt ist es, wenn eine Compileroption bedingte Ausdrücke mit booleschem Wert erzwingt, ohne das erzeugte JavaScript zu ändern.
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
- 25/100