microsoft / microsoft/TypeScript

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

Open
#60,822 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔎 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the provided example in the linked TypeScript Playground and compare the two if-statement forms described in the report. Review the compiler behavior for comma-separated expressions and constant conditions; done means the intended diagnostics or accepted behavior are defined and covered for these examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.