microsoft / microsoft/TypeScript

if-statements allow multiple arguments and don't check for constant conditions after the first argument

Offen
#60,822 8 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

🔎 Search Terms

"if statement", "constant condition"

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about common bugs
⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBBIFsCmBhAFk4BrAlmA5gGICuYwUO4MAvDABQAOAhgE5MICMAXHFC3vgA0MZmwQAmHtH4FhIBhXBMANgAVW7AMw0YfYkgCUNAHwwA3gCgY1mAHpbMACYhexAGZurNlkijEWYLos+gDcFgC+Fhb2MCoA7kwAnhAwbioQSMI+EMTKsCBucIioGNgCJGSKgfFJKTj4YCA+jhY4bnTwyOiYuAQV5JRgdABEouwcw8KjGhLDBsJpyhlGljYwEVExjkgMSGDbYPmB2bn5hZ0lPeWkA+Ct7RfdZX03VSNjnJMw02LiX4vLFZeawRIA

💻 Code
const someCheckingFunction = (param1: string, param2: string, optionalParam3 = true) => {
    // do stuff
    return true;
}

// always false, result of someCheckingFunction always ignored
if(someCheckingFunction("param1", "param2"), false) {
    
}

// dependent on result of someCheckingFunction
if(someCheckingFunction("param1", "param2", false)) {
    
}
🙁 Actual behavior

Due to a mistake in my bracket placement as seen in the example, I accidentally learned that multiple arguments in an if statement are possible.

Currently that means:

  1. only the last argument is used for the if statement check
  2. even for constant conditions there is not error visible
🙂 Expected behavior

What I would expect:

  1. don't allow multiple arguments, this only happens because someone made an error
  2. at least show an error if there is a constant condition
Additional information about the issue

No response

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das bereitgestellte Beispiel im verlinkten TypeScript Playground und vergleiche die beiden im Bericht beschriebenen Formen von if-Anweisungen. Überprüfe das Compilerverhalten für durch Kommas getrennte Ausdrücke und konstante Bedingungen; abgeschlossen ist die Aufgabe, wenn die vorgesehenen Diagnosen oder das akzeptierte Verhalten für diese Beispiele definiert und abgedeckt sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.