Building React Components Using Unions in TypeScript

This page summarizes the projects mentioned and recommended in the original post on dev.to

CodeRabbit: AI Code Reviews for Developers
Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.
coderabbit.ai
featured
Nutrient - The #1 PDF SDK Library
Bad PDFs = bad UX. Slow load times, broken annotations, clunky UX frustrates users. Nutrient’s PDF SDKs gives seamless document experiences, fast rendering, annotations, real-time collaboration, 100+ features. Used by 10K+ devs, serving ~half a billion users worldwide. Explore the SDK for free.
nutrient.io
featured
  1. proposal-pattern-matching

    Pattern matching syntax for ECMAScript

    More importantly, TypeScript typically commits to build things into itself when the proposal in JavaScript reaches Stage 3. The pattern matching proposal in JavaScript is Stage 1, but depends on many other proposals as well that may or may not need to be at Stage 3 as well for it to work. This particular proposal is interested on pattern matching on JavaScript Objects and other primitives, just like Python does with it’s native primitives. These are also dynamic types which helps in some areas, but makes it harder than others. Additionally, the JavaScript type annotations proposal needs to possibly account for this. So it’s going to be awhile. Like many years.

  2. CodeRabbit

    CodeRabbit: AI Code Reviews for Developers. Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.

    CodeRabbit logo
  3. TypeScript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    The common theme in a lot of React examples utilizes 2 types of data to build React components around: primitives and Objects. In this article, we’re going to talk about a 3rd called Discriminated Unions. We’ll go over what problems they solve, what their future looks like in JavaScript and possibly TypeScript, and what libraries can help you now.

  4. proposal-type-annotations

    ECMAScript proposal for type syntax that is erased - Stage 1

    More importantly, TypeScript typically commits to build things into itself when the proposal in JavaScript reaches Stage 3. The pattern matching proposal in JavaScript is Stage 1, but depends on many other proposals as well that may or may not need to be at Stage 3 as well for it to work. This particular proposal is interested on pattern matching on JavaScript Objects and other primitives, just like Python does with it’s native primitives. These are also dynamic types which helps in some areas, but makes it harder than others. Additionally, the JavaScript type annotations proposal needs to possibly account for this. So it’s going to be awhile. Like many years.

  5. ts-pattern

    🎨 The exhaustive Pattern Matching library for TypeScript, with smart type inference.

    ts-pattern

  6. purescript

    A strongly-typed language that compiles to JavaScript

    Naturally I’d recommend using a better language such as ReScript or Elm or PureScript or F#‘s Fable + Elmish, but “React” is the king right now and people perceive TypeScript as “less risky” for jobs/hiring, so here we are.

  7. effect

    An ecosystem of tools to build robust applications in TypeScript

    effect-ts

  8. ts-adt

    Generate Algebraic Data Types and pattern matchers

    ts-adt

  9. Nutrient

    Nutrient - The #1 PDF SDK Library. Bad PDFs = bad UX. Slow load times, broken annotations, clunky UX frustrates users. Nutrient’s PDF SDKs gives seamless document experiences, fast rendering, annotations, real-time collaboration, 100+ features. Used by 10K+ devs, serving ~half a billion users worldwide. Explore the SDK for free.

    Nutrient logo
  10. variant

    Variant types in TypeScript (by paarthenon)

    Variant

  11. rescript

    ReScript is a robustly typed language that compiles to efficient and human-readable JavaScript.

    This is because a “Tagged Union”, another word for TypeScript’s Discriminated Union, is a way to “tag which one is in use right now… we check the tag to see”. Just like when you’re shopping and check the tag of a piece of clothing to see what the price is, what size it is, or what material it’s made out of. Languages like ReScript compile many of their Unions (called Variants) to JavaScript Objects that have a tag property.

  12. pampy.js

    Pampy.js: Pattern Matching for JavaScript

  13. React

    The library for web and native user interfaces.

    The common theme in a lot of React examples utilizes 2 types of data to build React components around: primitives and Objects. In this article, we’re going to talk about a 3rd called Discriminated Unions. We’ll go over what problems they solve, what their future looks like in JavaScript and possibly TypeScript, and what libraries can help you now.

  14. fsharp.org

    The F# Software Foundation website

    Naturally I’d recommend using a better language such as ReScript or Elm or PureScript or F#‘s Fable + Elmish, but “React” is the king right now and people perceive TypeScript as “less risky” for jobs/hiring, so here we are.

  15. Fable: F# |> BABEL

    F# to JavaScript, TypeScript, Python, Rust and Dart Compiler

    Naturally I’d recommend using a better language such as ReScript or Elm or PureScript or F#‘s Fable + Elmish, but “React” is the king right now and people perceive TypeScript as “less risky” for jobs/hiring, so here we are.

  16. Elm

    Compiler for Elm, a functional language for reliable webapps.

    I get it. However, the whole point of using Unions to narrow your types, ensure only a set of possible scenarios can occur, and only access data of a particular union when it’s safe to do so. That’s some of what pattern matching can provide, and 100% of what using switch statements in TypeScript with their Discriminated Unions can provide. Yes, it’s not 100% exhaustive, but TypeScript is not soundly typed, and even Elm which is still has the same issue TypeScript does: You’re running in JavaScript where anything is possible. So it’s good enough to build with and much better than what you had.

  17. elmish

    Elm-like abstractions for F# apps

    Naturally I’d recommend using a better language such as ReScript or Elm or PureScript or F#‘s Fable + Elmish, but “React” is the king right now and people perceive TypeScript as “less risky” for jobs/hiring, so here we are.

  18. SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

    SaaSHub logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • TypeScript Enum's vs Discriminated Unions

    3 projects | dev.to | 12 Dec 2022
  • How to use Dependency Injection in Functional Programming

    5 projects | dev.to | 16 Jan 2022
  • How I host Elm web applications with GitHub Pages

    15 projects | dev.to | 17 Oct 2024
  • Type inference of local variable based on later operations

    3 projects | /r/ProgrammingLanguages | 10 Jun 2023
  • Announcing TypeScript 5.0

    3 projects | /r/programming | 16 Mar 2023

Did you know that TypeScript is
the 1st most popular programming language
based on number of references?