combining branches
See original GitHub issueInteresting 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:
- Created 3 years ago
- Comments:11 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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()
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 aoneOf
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