question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

combining branches

See original GitHub issue

Interesting library. I’ve been using this library: https://paarthenon.github.io/variant/ So my feedback comes from my experience with using that. One of its nice features is that you can combine branches: https://paarthenon.github.io/variant/docs/use/matching#-matcher

For example:

type FooBarBaz = {type: "foo"} | {type: "baz"} | {type: "bar"}
declare const foobarbaz: FooBarBaz;

swtich (foobarbaz.type) {
  case "foo":
  case "bar":
    // handle both foo and bar in a single branch
  case "baz: 
    // handle baz in its own branch 
}

// variant:

matcher(foobarbaz)
  .when(["foo", "bar"], (foobar) => {})
  .when({baz: (baz) => {} })
  .complete()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
gvergnaudcommented, Mar 1, 2021

I just publish the 2.2.1-next.2 pre-release which uses function overloads instead of middle rest arguments so it should work fine with all versions of TS now. The downside is that you can only pass up to 5 patterns to .with()

2reactions
gvergnaudcommented, Feb 26, 2021

I opened a PR implementing a way to give several patterns to .with() https://github.com/gvergnaud/ts-pattern/pull/18 . In the end I decided against having a oneOf helper because it complexifies the inference of the pattern type.

I published a pre-release (2.2.1-next.1), but it will only work for TS >= v4.2. I might make it TS v4 compatible before merging by using function overloads instead of using middle rest function arguments.

Feel free to try it and to give me your feedback

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic Branching and Merging - Git SCM
Let's go through a simple example of branching and merging with a workflow that you ... After it's tested, merge the hotfix branch,...
Read more >
Merging 2 branches together in GIT - Stack Overflow
merge is used to bring two (or more) branches together. a little example: # on branch A: # create new branch B $...
Read more >
Git Merge | Atlassian Git Tutorial
Git merge will combine multiple sequences of commits into one unified history. In the most frequent use cases, git merge is used to...
Read more >
Branch and Merge - Essential skills for reproducible research ...
To do a merge (locally), git checkout the branch you want to merge INTO. Then type git merge <branch> where <branch> is the...
Read more >
How To Combine Branches With Git ... - Adam the Automator
Merging Git Branches Locally · 1. Run the git checkout command below to switch to the master branch since you'll update it with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found