basarat / basarat/typescript-book
Ternary Operator with destructuring
- Dominant language
- TypeScript
- Stars
- 21.6k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
From http://blog.johnnyreilly.com/2016/08/the-ternary-operator-meets-destructuring.html?m=1
By @johnnyreilly :rose:
``` ts
const { legWear, coat } = weather === "good"
? { legWear: "shorts", coat: false }
: { legWear: "jeans", coat: true }
```
FWIW I've done the following historically.
``` ts
const thisOrThat = (someCondition) ? "this" : "or that"
const thisOrThatAnother = (someCondition) ? "thisAnother" : "or thatAnother"
```
But I like what John's done better :heart:
> add to tips
Contributor guide
Research direction
Locate the book's tips section and review how similar TypeScript examples are presented. Add the supplied ternary-with-destructuring example and verify that the wording and formatting fit the surrounding content; done means the tip is included in the book.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100