HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
tc39
proposal-pattern-matching
HTML2017–2026
tc39 / proposal-pattern-matching

proposal-pattern-matching

Pattern matching syntax for ECMAScript

37Distinct people
41Mentions
0Explicit recommenders
5.8KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Pattern matching syntax for ECMAScript

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 1:49:46 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year41 dated mentions

Observed mentions: 2017-07-05 15:08:01 UTC to 2026-02-01 20:35:39 UTC.

024682017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 3 mentions; 1 submissions, 2 comments20172018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 4 mentions; 2 submissions, 2 comments2019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 4 mentions; 0 submissions, 4 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 5 mentions; 0 submissions, 5 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 8 mentions; 2 submissions, 6 comments20212022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 4 mentions; 0 submissions, 4 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 7 mentions; 0 submissions, 7 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 4 mentions; 1 submissions, 3 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 1 mentions; 1 submissions, 0 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC312
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC422
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC404
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC505
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC826
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC404
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC707
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC101
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC413
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC110

From the project README

An excerpt from the repository, fetched Nov 13, 2026.

Read the project’s introduction
ECMAScript Pattern Matching Status Stage: 1 Spec Text: https://tc39.github.io/proposal-pattern-matching Authors: Originally Kat Marchán (Microsoft, @zkat__); now, the below champions. Champions: (in alphabetical order) Daniel Rosenwasser (Microsoft, @drosenwasser) Jack Works (Sujitech, @Jack-Works) Jordan Harband (HeroDevs, @ljharb) Mark Cohen (@mpcsh_) Ross Kirsling (Sony, @rkirsling) Tab Atkins-Bittner (Google, @tabatkins) Introduction Problem There are many ways to match values in the language, but there are no ways to match patterns beyond regular expressions for strings. However, wanting to take different actions based on patterns in a given value is a very common desire: do X if the value has a foo property, do Y if it contains three or more items, etc. Current Approaches switch has the desired structure -- a value is given, and several possible match criteria are offered, each with a different associated action. But it's severely lacking in practice: it may not appear in expression position; an explicit break is required in each case to avoid accidental fallthrough; scoping is ambiguous (block-scoped variables inside one case are available in the scope of the others, unless curly braces are used); the only comparison it can do is ===; etc. if/else has the necessary power (you can perform any comparison you like), but it's overly verbose even for common cases, requiring the author to explicitly list paths into the value's structure multiple times, once per test performed. It's also statement-only (unless the author opts for the harder-to-understand ternary syntax) and requires the value under test to be stored in a (possibly temporary) variable. Priorities for a solution This section details this proposal’s priorities. Note that not every champion may agree with each priority. Pattern matching The pattern matching construct is a full conditional logic construct that can do more than just pattern matching. As such, there have been (and there will be more) trade-offs that need to be made. In those cases, we should prioritize the ergonomics of structural pattern matching over other capabilities of this construct. Subsumption of switch This feature must be easily searchable, so that tutorials and documentation are easy to locate, and so that the feature is easy to learn and recognize. As such, there must be no syntactic overlap with the switch statement. This proposal seeks to preserve the good parts of switch, and eliminate any reasons to reach for it. Be better than switch switch contains a plethora of footguns such as accidental case fallthrough and ambiguous scoping. This proposal should eliminate those footguns, while also introducing new capabilities that switch currently can not provide. Expression semantics The pattern matching construct should be usable as an expression: return match { ... } let foo = match { ... } () => match { ... } etc. The value of the whole expression is the value of whatever clause is matched. Exhaustiveness and ordering If the developer wants to ignore certain possible cases, they should specify that explicitly. A development-time error is less costly than a production-time error from something further down the stack. If the developer wants two cases to share logic (what we know as "fall-through" from switch), they should specify it explicitly. Implicit fall-through inevitably silently accepts buggy code. Clauses should always be checked in the order they’re written, i.e. from top to bottom. User extensibility Userland objects should be able to encapsulate their own matching semantics, without unnecessarily privileging builtins. This includes regular expressions (as opposed to the literal pattern syntax), numeric ranges, etc. Prior Art This proposal adds a pattern matching expression to the language, based in part on the existing Destructuring Binding Patterns. This proposal was approved for Stage 1 in the May 2018 TC39 meeting, and slides for that presentation are available here. Its current form was presented to TC39 in the April 2021 meeting (slides). This proposal draws from, and partially overlaps with, corresponding features in CoffeeScript, Rust, Python, F#, Scala, Elixir/Erlang, and C++. More recently, Flow has gained a feature closely matching and clearly inspired by the syntax proposed here. Userland matching A list of community libraries that provide similar matching functionality: Optionals — Rust-like error handling, options and exhaustive pattern matching for TypeScript and Deno ts-pattern — Exhaustive Pattern Matching library for TypeScript, with smart type inference. babel-plugin-proposal-pattern-matching — Minimal grammar, high performance JavaScript pattern matching implementation. match-iz — A tiny functional pattern-matching library inspired by the TC39 proposal. patcom — Feature parity with TC39 proposal without any new syntax Specification This proposal introduces three new concepts to Javascript: the "matcher pattern", a new DSL closely related to destructuring patterns, which allows recursively testing the structure and contents of a value in multiple ways at once, and extracting some of that structure into local bindings at the same time the match(){} expression, a general replacement for the switch statement that uses matcher patterns to resolve to one of several values, the is boolean operator, which allows for one-off testing of a value against a matcher pattern, potentially also introducing bindings from that test into the local environment. Matcher Patterns Matcher patterns are a new DSL, closely inspired by destructuring patterns, for recursively testing the structure and contents of a value while simultaneously extracting some parts of that value as local bindings for use by other code. Matcher patterns can be divided into three general varieties: Value patterns, which test that the subject matches some criteria, like "is the string "foo"" or "matches the variable bar". Structure patterns, which test the subject
Read the full README on GitHub

What Hacker News says

41 sources
I'm waiting for pattern matching to be added to JS. The proposal[1] documents a lot of thought on how to add pattern matching to a language, including prior art in other languages. (Pattern matching was introduced to me via either F# or Erlang/Elixir.) DeltaScript pattern matching seems to be missing two major features; perhaps intentional because the implementation is more difficult: 1. Binding - useful to be able to assign variables to sub-parts of the control value. 2. Structural matching - matching based on the shape of the control value. I suppose both binding and structural matching can be accomplished with more verbose `passes` tests. (Also some redundant code to get the bindings; perhaps the `passes` test could return optional bindings.) [1]: https://github.com/tc39/proposal-pattern-matching
In Show HN: Switch statement + lambdas = pattern matching in DeltaScript
We often add promising TC39 proposals into Civet so people can experiment without waiting. We've added https://github.com/tc39/proposal-pipeline-operator, a variant of https://github.com/tc39/proposal-pattern-matching, a variant of https://github.com/tc39/proposal-string-dedent and others. Since our goal is to be 99% compatible with ES we'll need to accommodate any proposals that become standard and pick up anything TC39 leaves on the table (rest parameters in any position, etc.)
In CoffeeScript for TypeScript

Showing the 15 most recent of 41 sources. Enable JavaScript to search and browse every indexed mention.

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.