GitPedia

Variant

Variant types in TypeScript

From paarthenon·Updated May 24, 2026·View on GitHub·

> [A variant type](https://reasonml.github.io/docs/en/variant) is like an enum but each case can hold some extra data. The project is written primarily in TypeScript, distributed under the Mozilla Public License 2.0 license, first published in 2019. Key topics include: adt, algebraic-data-type, discriminated-unions, dispatching, flux.

Latest release: 2.0.1Variant 2.0.1
October 29, 2020View Changelog →

Variant Build Status npm NPM

A variant type is like an enum but each case can hold some extra data.

bash
npm i -S variant

Variant aims to bring the experience of variant types to TypeScript. Variant types, a.k.a. discriminated unions in the TypeScript world, are an excellent tool for describing and handling flexible domain models and tiny DSLs. However, because "TypeScript instead builds on JavaScript patterns as they exist today" using them as-is can result in tedious and fragile code. This project addresses that by providing well-typed, fluent, and expressive tools to safely do away with the boilerplate.

Variant Logo Documentation

✨ Variant 3.0 is in active development. Documentation featuring 3.0 features will be available shortly. In the meantime, the changes are available here.

everything below this line is project documentation for developers. Please use the website linked just above.


Initial setup

bash
npm install

build

bash
npm run build

test

bash
npm test

Questions, comments, and contributions are welcome. Open an issue.

Contributors

Showing top 3 contributors by commit count.

View all contributors on GitHub →

This article is auto-generated from paarthenon/variant via the GitHub API.Last fetched: 6/20/2026