RepositoryTypeScriptUSUnited States
paarthenon

paarthenon/variant

Variant types in TypeScript

193stars
3forks
14issues
2views

Variant Build Status npm NPM

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

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

npm install

build

npm run build

test

npm test

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

Similar Projects

Discover other similar projects and AI models.

RepositoryC#
mknejp/dotvariant

A type-safe and space-efficient sum type for C# (comparable to discriminated unions in C or C++)

73
Jun 30, 2026
RepositoryTypeScript
n8n-io/n8n

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

213.0k
Dec 3, 2026
RepositoryTypeScript
microsoft/vscode

Visual Studio Code

195.9k
Nov 30, 2026
RepositoryJavaScript
paularmstrong/normalizr

Normalizes nested JSON according to a schema

20.8k
Mar 19, 2022
RepositoryJavaScript
kdchang/reactjs101

從零開始學 ReactJS(ReactJS 101)是一本希望讓初學者一看就懂的 React 中文入門教學書,由淺入深學習 React.js 生態系 (Flux, Redux, React Router, ImmutableJS, React Native, Relay/GraphQL etc.)。

4.3k
Oct 11, 2023
RepositoryC#
domn1995/dunet

C# discriminated union source generator

886
Nov 16, 2026
RepositoryC++
mpark/variant

C++17 `std::variant` for C++11/14/17

716
Dec 7, 2022
RepositoryC++
eggs-cpp/variant

Eggs.Variant is a C++11/14/17 generic, type-safe, discriminated union.

141
Feb 2, 2022
RepositoryC++
cbeck88/strict-variant

A realtime/embedded-friendly C++11 variant type which is never empty and prevents undesirable implicit conversions

102
Aug 8, 2018